Protecting as part of a macro

  • Thread starter Thread starter Brian Ferris
  • Start date Start date
B

Brian Ferris

Hi there,

I have a series of steps in a macro which is in turn
assigned to a command button.

I would like the last step to be protecting the workbook
however with a given password. Is there some way i can
write the password in the macro.

The whole idea is that when pressing he button , the first
thing would involve unprotecting the sheet, but I would
like the user to be prompted for a password to unprotect
at this stage. this can only be done by entering the
password when protecting the workbook in the first place.
The reason for unprotecting and protecting back again at
the end is that the macro can not run on a protected
sheet...

Any suggestions...

Thanks in advance..

Brian
 
To unprotect the sheet with a password, use the following line of code:

ActiveSheet.Unprotect Password:="dog"

To protect it with a password, use the following:

ActiveSheet.Protect Password:="dog", DrawingObjects:=True, Contents:=True,
Scenarios:=True

Obviously change the password to your password. And be advised, the settings
in the above (for protecting) may be slightly different for your situation
(i.e., you may have more or less items being protected).

MRO
 
Brian,

Do you just mean

ActiveWorkbook.Protect Password:="Bob", Structure:=True, Windows:=False
 
Back
Top