Protecting as part of a macro

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
 
R

Rafael Ortiz

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
 
B

Bob Phillips

Brian,

Do you just mean

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top