PDA

View Full Version : [SOLVED:] Protect method



K. Georgiadis
03-18-2005, 09:55 AM
in the following line of code (from a worksheet protect macro):


mySheet.Protect "Password", True, True, True

do the three "true" statements refer to drawing objects, contents and scenarios?

Zack Barresse
03-18-2005, 10:00 AM
Yes. :yes

K. Georgiadis
03-18-2005, 10:07 AM
Thanks, Zack. It never hurts to receive confirmation from an expert

mvidas
03-18-2005, 10:12 AM
Whenever I protect a sheet via code, I always include the UserInterfaceOnly argument. What this does is protect the sheet from the user after it is run, but allows vba code to run as if the sheet were unprotected. Note, though, that this only applies to that specific instance of the file being opened. If you protect it with UserInterfaceOnly, save the file, and close it, when you re-open the file it will have to be re-protected with UserInterfaceOnly for the benefits to apply. A note from the help files:

If you apply the Protect method with the UserInterfaceOnly argument set to True to a worksheet and then save the workbook, the entire worksheet (not just the interface) will be fully protected when you reopen the workbook. To unprotect the worksheet but re-enable user interface protection after the workbook is opened, you must again apply the Protect method with UserInterfaceOnly set to True.

You can set it using an additional True argument, like:

mySheet.Protect "Password", True, True, True, True
Or, to make sure you understand what is being sent to the Protect method, you could specify the arguments:

mySheet.Protect "Password", DrawingObjects:=True, Contents:=True, _
Scenarios:=True, UserInterfaceOnly:=True

K. Georgiadis
03-18-2005, 10:22 AM
thanks for the tips. The worksheet protection macro that I normally use specifies the arguments as you recommend