Locking all sheets with macro........works, but first sheet different than rest.

jimbofoxman

New Member
Joined
Feb 23, 2018
Messages
13
So I found lots of references to this kinda code for locking all sheets at once.

Code:
Sub ProtectAll()

    Dim wSheet As Worksheet
    Dim Pwd As String

    Pwd = InputBox("Enter your password to protect all worksheets", "Password Input")

    For Each wSheet In Worksheets
        wSheet.Protect Password:=Pwd
    Next wSheet
    
End Sub

While it does lock all sheets, it doesn't lock them all the same. If I were to lock a sheet from the ribbon "Protect Sheet" button, the only two boxes I have checked are "Protect worksheet and contents of locked cells" and "Select Unlocked cells" from the lower check box list.

Then the user can only select and type the fields I have unlocked. They cannot select locked fields, say a formula cell.

When I use the macro, it locks the first page like above but all the rest of the sheets any cell can be selected. But even though any cell can be selected if it's locked they cannot change it..........so essentially it still is locked. A message pops up say You cannot change the cell as it's protected, blah blah blah. So it's locked.

It may be trivial, but I'd like it to lock all sheets like the first one, where only unlocked cells can be selected. I tried adding "Contents:=True" to the wSheet.Protect line but that didn't do anything to help.

Is their anything that can be done? Or is it just one of the downfalls of locking multiple sheets at once with code? In this case, probably 90 sheets.

Thanks,

Jim
 
Silly me........it wall works now. Added Mark858's change. Also, I failed to understand the Personal Workbook creation. Once I figured that out it all worked just fine.

Thanks to everyone for the input!

Jim
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,216,744
Messages
6,132,471
Members
449,729
Latest member
davelevnt

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