unprotect with password not working

bubbafish

Board Regular
Joined
Jan 20, 2004
Messages
120
Any suggestions?
I am needing to turn off the PW protection on a worksheet before I do a copy.
I have the same code for other sheets and it works fine. For some reason on this sheet
if I have it pass protected with "mypw" and run the macro below I get a runtime error of 1004 (password supplied is incorrect). I can go into Tools, Protection, Unprotect sheet and type in the same PW without any problems. I can change the unprotect to Protect and it will set it, I just cant remove it when I do my copy

????


Sub test1()
Turn off PW on Sales Sheet
ActiveSheet.Unprotect Password:=mypw
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Assuming that mypw is not a declared variable, did you try this?
Rich (BB code):
ActiveSheet.Unprotect Password:="mypw"

I recommend that you enforce variable declaration by adding Option Explicit to the top of your code modules. You can have this automatically done for you by opening the Visual Basic Editor, then Tools | Options | Editor Tab and ticking "Require Variable Declaration". It will save you hours of headaches! ;)
 
Upvote 0

Forum statistics

Threads
1,215,020
Messages
6,122,712
Members
449,093
Latest member
Mnur

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