Hi all!
I'm running the following code using a 'one-click button' and want to add the 'unprotect_all_sheets' code below to be the first code run when clicked. When I add it to the one-click button codes it will not work; if I use it independently the code works fine.
CODE THAT WORKS:
TRYING TO ADD THIS TO THE ONE-CLICK CONTROL:
I'm running the following code using a 'one-click button' and want to add the 'unprotect_all_sheets' code below to be the first code run when clicked. When I add it to the one-click button codes it will not work; if I use it independently the code works fine.
CODE THAT WORKS:
VBA Code:
Private Sub CommandButton1_Click()
End Sub
Sub Dosomething()
Dim xSh As Worksheet
Application.ScreenUpdating = False
For Each xSh In Worksheets
If xSh.Visible = xlSheetVisible Then Call RunCode(xSh)
Next
Application.ScreenUpdating = True
End Sub
Sub RunCode(sht As Worksheet)
Dim lr As Long, e As Range
With sht
lr = .Range("A" & .Rows.Count).End(xlUp).Row
On Error Resume Next
For Each e In .Range("A1:A" & lr).SpecialCells(xlFormulas)
If Len(e) = 0 Then .Rows(e.Row).Hidden = True
Next
On Error GoTo 0
End With
End Sub
TRYING TO ADD THIS TO THE ONE-CLICK CONTROL:
VBA Code:
Sub Unprotect_All_Sheets()
'declare a variable
Dim ws As Worksheet
'loop through each worksheet in this workbook and unprotect them using the same password that was used to protect them
For Each ws In ThisWorkbook.Worksheets
ws.Unprotect Password:="correct pw entered here"
Next ws
End Sub