Macro to password protect

G

Guest

Hi,

Is it possible to run a macro from a button to password protect a file?
and similarly is it possible to remove the password protection from a button?

thankyou for your help.
 
G

Guest

Patrick,

you can do something like this.

'Protect/Unprotect a sheet
Worksheets("Sheet1").Protect Password:="password"
Worksheets("Sheet1").Unprotect Password:="password"

'Protect/Unprotect the active workbook
ActiveWorkbook.Protect Password:="password"
ActiveWorkbook.Unprotect Password:="password"


Lookup the Protect and Unprotect methods in the VBA help for more details on
the available parameters.
 
A

aidan.heritage

Patrick,

you can do something like this.

'Protect/Unprotect a sheet
Worksheets("Sheet1").Protect Password:="password"
Worksheets("Sheet1").Unprotect Password:="password"

'Protect/Unprotect the active workbook
ActiveWorkbook.Protect Password:="password"
ActiveWorkbook.Unprotect Password:="password"

Lookup the Protect and Unprotect methods in the VBA help for more details on
the available parameters.

--
Hope that helps.

Vergel Adriano







- Show quoted text -

might also be worth mentioning that it's PROBABLY sensible to password
protect your code as IF the reason for the protection unprotection is
to keep the password secret, all the user needs to do with unprotected
code is view it to find out what the password is.
 
G

Guest

Thankyou for you help much appreciated

might also be worth mentioning that it's PROBABLY sensible to password
protect your code as IF the reason for the protection unprotection is
to keep the password secret, all the user needs to do with unprotected
code is view it to find out what the password is.
 

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