Macro to unprotect worksheet not working

phad012

New Member
Joined
Oct 28, 2017
Messages
5
Hi,

I'm sure there is a simple solution, but I've been Googling this for almost an hour.

I need a macro to unprotect, then re-protect, a worksheet. The following doesn't seem to work:

Sub Unprotect ()

ActiveSheet.Unprotect Password: "my password typed here"

End sub

When I run the macro, the following error pops up:

Run-time error '1004'
Application-defined or object-defined error

I think I'm using Excel 2013.

I checked to make sure the password is correct a number of times, and also checked the correct sheet was being selected.

Many thanks
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Sorry the code should read:

ActiveSheet.Unprotect Password: ="my password typed here"

I missed the '=' sign in my post
 
Upvote 0
This should work fine:

ActiveSheet.Unprotect Password:="PasswordHere"

But if you want to shorthand it, you don't need the Password qualifier:

ActiveSheet.Unprotect "PasswordHere"

You might want to check the quotes, VBA often doesn't like them when they're copied from browsers.

EDIT: That code won't care what version you're on, but if you're not sure, you can go to File > Account to check.

HTH
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,021
Latest member
Justyna P

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