exclude 1 sheet in wkb

lbozeman

New Member
Joined
May 2, 2011
Messages
1
How can I make it so the below macro sets all sheets to password except 1? I would like sheet1 to have the password: password1 and all other to have password.

Any help is welcomed.


Sub ProtectAllLB()
top:
pass = "password"
repass = "password"
If Not (pass = repass) Then
MsgBox "Passwords do not match"
GoTo top
End If

For i = 1 To Worksheets.Count
If Worksheets(i).ProtectContents = True Then GoTo err
Next

For Each s In ActiveWorkbook.Worksheets
s.Protect Password:=pass, UserInterfaceOnly:=True
Next

Run "RemoveToolbars"
ActiveWorkbook.Save
Application.StatusBar = "Dashboard Updated and Saved successfully, Thank you."

MsgBox "Dashboard Save Completed.", vbInformation

Exit Sub

err: MsgBox "Please unprotect all sheets before running this Macro."
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
You can test the name of each worksheet as you loop through them - something along these lines:-
Code:
For Each s In ActiveWorkbook.Worksheets
  if s.[COLOR=black]name="fred" then[/COLOR]
    s.Protect Password:="password1", UserInterfaceOnly:=True
  else
    s.Protect Password:="password", UserInterfaceOnly:=True
  endif
Next
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,777
Members
452,942
Latest member
VijayNewtoExcel

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