Password protecting a sheet, while allowing vba to freely unprotect

Yeoman.jeremy

Board Regular
Joined
Apr 4, 2011
Messages
90
Hi there.

I have recently encountered a problem with my excel program, in which the manager of a particular shop is being very sour about change, and it is my impression that he is purposefully unprotecting and protecting the sheet again after mucking around with little bits of formulae.

I know that I can use a password to prevent people other than myself to unprotect the sheet, but this isn't ideal, as my vba coding requires the unprotecting and protecting of the sheet. is there a way that i can get around having to type in the password everytime i use a piece of code?

Many thanks
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
If you protect the worksheet with VBA, one of the arguments of Protect is UserInterfaceOnly. When set to TRUE, VBA code can access all aspects of the sheet without unprotecting it, while users will be restricted.

Example:
Code:
ActiveSheet.Protect Password:="guesswhat", UserInterfaceOnly:=True

Does that help?
 
Upvote 0
Wait, so let me get this straight
If i used the formula you just gave me to protect my sheets instead of through the options, vba ignores the protection when it does it's workings?
 
Upvote 0
Wait, so let me get this straight
If i used the formula you just gave me to protect my sheets instead of through the options, vba ignores the protection when it does it's workings?
That is correct. Your program can run roughshod all over the worksheet as if it's not protected. The users, on the other hand will be hobbled by whatever restrictions you included in the protection settings.
 
Upvote 0
Oh my goodness!
This is such a huge help!

Up until now, I've been including the ridiculous amounts of unprotecting and protecting within each module.
:rofl::rofl::laugh:

ahhhh thank you very kindly
 
Upvote 0
I just had a thought..

If the vba will ignore the protection when coded, can i still use (as an example)

Code:
ActiveSheet.UsedRange = ""

does the "UsedRange" relate to only the unlocked cells, or the cells that can be changed?
 
Upvote 0
I just had a thought..

If the vba will ignore the protection when coded, can i still use (as an example)

Code:
ActiveSheet.UsedRange = ""

does the "UsedRange" relate to only the unlocked cells, or the cells that can be changed?
Just try it and see...(save your work first, of course)
 
Upvote 0
When in the VBA editor...
You *did* reference a worksheet...right?
Like in my example:
ActiveSheet.Protect Password:="guesswhat", UserInterfaceOnly:=True
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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