ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to password protect (https://www.excelbanter.com/excel-programming/396462-macro-password-protect.html)

Patrick Bateman

Macro to password protect
 
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.

Vergel Adriano

Macro to password protect
 
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


"Patrick Bateman" wrote:

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.


[email protected]

Macro to password protect
 
On 28 Aug, 16:46, Vergel Adriano
wrote:
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



"Patrick Bateman" wrote:
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.- Hide quoted text -


- 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.


Patrick Bateman

Macro to password protect
 
Thankyou for you help much appreciated

" wrote:

On 28 Aug, 16:46, Vergel Adriano
wrote:
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



"Patrick Bateman" wrote:
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.- Hide quoted text -


- 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.




All times are GMT +1. The time now is 05:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com