Hi all,
I am having a problem with the below code. It is supposed to unprotect the workbook and then unprotect each worksheet in the workbook. If I run the "unlockcells" macro directly it works fine, but... I have a userform with various options, if you click the "UnlockButton" it simply closes the userform and calls the macro. If you do it this way the macro seems to run, all the sheets unprotect but the Workbook its self remains protected.
Any ideas why the Workbook won't unprotect if the macro is called from the userform?
In Userform:
Private Sub UnlockButton_Click()
Unload AdminMainMenu
Call unlockcells
End Sub
In Main code module:
Sub unlockcells()
Dim i As Integer
Application.ScreenUpdating = False
ActiveWorkbook.Unprotect Password:=PWord("FGXGNQR")
For i = 1 To Worksheets.Count
Worksheets(i).Unprotect Password:=PWord("FGXGNQR")
Next i
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
Worksheets("Variables and Setup").Activate
ActiveWindow.DisplayWorkbookTabs = True
End Sub
I am having a problem with the below code. It is supposed to unprotect the workbook and then unprotect each worksheet in the workbook. If I run the "unlockcells" macro directly it works fine, but... I have a userform with various options, if you click the "UnlockButton" it simply closes the userform and calls the macro. If you do it this way the macro seems to run, all the sheets unprotect but the Workbook its self remains protected.
Any ideas why the Workbook won't unprotect if the macro is called from the userform?
In Userform:
Private Sub UnlockButton_Click()
Unload AdminMainMenu
Call unlockcells
End Sub
In Main code module:
Sub unlockcells()
Dim i As Integer
Application.ScreenUpdating = False
ActiveWorkbook.Unprotect Password:=PWord("FGXGNQR")
For i = 1 To Worksheets.Count
Worksheets(i).Unprotect Password:=PWord("FGXGNQR")
Next i
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
Worksheets("Variables and Setup").Activate
ActiveWindow.DisplayWorkbookTabs = True
End Sub