Workbook Protection not working when called from Userform

dr_drews

New Member
Joined
Dec 18, 2004
Messages
16
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
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I'm just throwing out a suggestion here.

Perhaps try calling unlockcells before unloading AdminMainMenu. Maybe somethings don't get completed after the userform is unloaded. Again, just a shot in the dark that's easy to test.

Code:
Private Sub UnlockButton_Click()
    Call unlockcells
    Unload AdminMainMenu
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,691
Members
452,938
Latest member
babeneker

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top