Hello,
I have a macro setup to protect and unprotect all sheets in a workbook. I have half of this working... This portion locks all of the sheets with a specified password, and they must know the password to do so. This locks all sheets and collapses the groupings as it should.
Sub Button1_Click()
Dim objSheet As Worksheet
Dim pw As String
pw = InputBox("Please Enter Password", "Password")
If pw = "XXX" Then
'Protecting all worksheets with password
For Each objSheet In Worksheets
objSheet.Outline.ShowLevels RowLevels:=0, ColumnLevels:=1
If objSheet.ProtectContents = False Then objSheet.Protect DrawingObjects:=True, _
Contents:=True, Scenarios:=True, AllowFiltering:=True, Password:="XXX"
Next objSheet
Workbooks("Macros.xlsm").Close (SaveChanges = No)
MsgBox ("Complete")
Else: MsgBox ("Invalid Password")
End If
End Sub
However, This code which is for unlocking the sheets, I want it to expand all groupings.... it is not doing so as I thought it would.
Sub Button2_Click()
Dim objSheet As Worksheet
Dim pw As String
pw = InputBox("Please Enter Password", "Password")
If pw = "XXX" Then
'UnProtecting all worksheets with password
For Each objSheet In Worksheets
If objSheet.ProtectContents = True Then objSheet.Unprotect pw
objSheet.Outline.ShowLevels 8
Next objSheet
Workbooks("Macros.xlsm").Close (SaveChanges = No)
Else: MsgBox ("Invalid Password")
End If
MsgBox ("Complete")
End Sub
Where am I going wrong with the ungrouping? I would think it should work much as the grouping portion does correctly.
Bookmarks