Embed un-protect password in a macro?

gidsy

Board Regular
Joined
Jan 13, 2005
Messages
142
Hi,

Is there a way I can unprotect a sheet at the beginning and then protect it again at the end of a macro? I want the sheet to have a password.

Cheers.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi Gidsy
Try
Code:
ws.Unprotect "password"
at the beginning of the code

AND

Code:
ws.Protect "password"
at the end ....change "password" to whatever you want as your password
 
Upvote 0
Many thanks....this works...

Do you have code that will set the options when you protect the sheet again....e.g. edit cells, delete rows etc...?
 
Upvote 0
Depending on which settings you want....simply use the macro recorder to select the settings and then copy and paste to the rest of your macro.
Like
Code:
ws.Protect "password", DrawingObjects:=True, Contents:=True, Scenarios:=True _
        , AllowFormattingRows:=True, AllowDeletingRows:=True, AllowSorting:=True
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,809
Members
452,944
Latest member
2558216095

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