protecting, unprotecting workbook macro error

mike_ate_a_pie

Board Regular
Joined
Sep 25, 2009
Messages
69
i have this code found on the net for protecting/unprotecting my workbook, however i am unable to work out the password, i have tried Password Input and changing it to other passwords but cant figure out what i'm missing.

sure it must be simple but just cant see it,

any help appreciated

thanks


Option Explicit

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

Sub UnProtectAll()

Dim wSheet As Worksheet
Dim Pwd As String

Pwd = InputBox("Enter your password to unprotect all worksheets", "Password Input")
On Error Resume Next
For Each wSheet In Worksheets
wSheet.Unprotect Password:=Pwd
Next wSheet
If Err <> 0 Then
MsgBox "You have entered an incorect password. All worksheets could not " & _
"be unprotected.", vbCritical, "Incorect Password"
End If
On Error Goto 0

End Sub </pre>
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
i havent ran the Protect ALl this was copied from another help website.

is there a alternative way to do this?

cheers
 
Upvote 0
I am trying to protect the entire workbook from being edited.

I would like to include one button to protect the workbook and another for unprotecting the workbook and allowing the user to make changes. With both buttons being password protected with the same password.

Hope this helps

thanks :)
 
Upvote 0
So assign ProtectAll and UnProtectAll to your buttons. Click the one for ProtectAll. Be sure to remember the password you entered. Then click the one for UnProtectAll and enter the password.
 
Upvote 0
cool, i've now got it to work , however is there any way to stop the unprotect macro scanning through every worksheet, even if it paused on the same page as this would appear a lot more professional.

thanks
 
Upvote 0
Application.ScreenUpdating=False before the loop, and change back to True after the loop.
 
Upvote 0
Hi again,

I just realsied that when i protect my sheet for some reason some macro buttons still work which is desired but others dont and come up as needing debugged! Is there any reason for this and how can I make the macro buttons work when the sheet is protected?

Thanks

Mike
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,484
Members
448,967
Latest member
visheshkotha

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