Jaspal
06-28-2013, 07:19 AM
Hello there,
I have two public macro's to protect and unprotect my sheet, which I use in other macros using "Call". I want users to be able to click "+" to group/ungroup columns and rows.
Public Sub UnprotectSheet(sWhichSheet)
' This MAcro unprotects the sheet
If Sheets(sWhichSheet).ProtectContents = True Then
Sheets(sWhichSheet).Unprotect Password:=sProtectionPassword
End If
End Sub
Public Sub ProtectSheet(sWhichSheet)
' This Macro protects the Sheet
If Sheets(sWhichSheet).ProtectContents = False Then
Sheets(sWhichSheet).Protect Password:=sProtectionPassword, DrawingObjects:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True, AllowDeletingRows:= _
True
End If
End Sub
I tried using the below code in the Workbook_open, but it does not work. I get an error message that to group/ungroup i need to unprotect my sheet. I have also checked "Enable AutoFilter" in the protect worksheet option.
Private Sub Workbook_Open()
With Worksheets(Detailed)
.Protect Password:="protect", UserInterfaceOnly:=True
.EnableOutlining = True
End With
End Sub
I also tried, but it does not work either
Private Sub Workbook_Open()
With Worksheets("Detailed")
Call UnprotectSheet(ActiveSheet.Name)
.Protect Password:="protect", UserInterfaceOnly:=True
.EnableOutlining = True
End With
Call ProtectSheet(ActiveSheet.Name)
End Sub
Thank you in advance for help.
I have two public macro's to protect and unprotect my sheet, which I use in other macros using "Call". I want users to be able to click "+" to group/ungroup columns and rows.
Public Sub UnprotectSheet(sWhichSheet)
' This MAcro unprotects the sheet
If Sheets(sWhichSheet).ProtectContents = True Then
Sheets(sWhichSheet).Unprotect Password:=sProtectionPassword
End If
End Sub
Public Sub ProtectSheet(sWhichSheet)
' This Macro protects the Sheet
If Sheets(sWhichSheet).ProtectContents = False Then
Sheets(sWhichSheet).Protect Password:=sProtectionPassword, DrawingObjects:=True, Contents:=True, Scenarios:=True, UserInterfaceOnly:=True, AllowDeletingRows:= _
True
End If
End Sub
I tried using the below code in the Workbook_open, but it does not work. I get an error message that to group/ungroup i need to unprotect my sheet. I have also checked "Enable AutoFilter" in the protect worksheet option.
Private Sub Workbook_Open()
With Worksheets(Detailed)
.Protect Password:="protect", UserInterfaceOnly:=True
.EnableOutlining = True
End With
End Sub
I also tried, but it does not work either
Private Sub Workbook_Open()
With Worksheets("Detailed")
Call UnprotectSheet(ActiveSheet.Name)
.Protect Password:="protect", UserInterfaceOnly:=True
.EnableOutlining = True
End With
Call ProtectSheet(ActiveSheet.Name)
End Sub
Thank you in advance for help.