ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Protecting Sheets (https://www.excelbanter.com/excel-programming/278660-protecting-sheets.html)

PeteD

Protecting Sheets
 
Hi,

Is it possible to protect/unprotect a sheet with a
password in VBA?. Example please if any.

Thanks
PeteD

Jill[_6_]

Protecting Sheets
 
Pete,

Here is a sample that I use.
At the start of the code I unprotect the sheets so the
rest of my code can run:

Sheets("Raw Data").Select
ActiveSheet.Unprotect Password:="yourpassword"
Sheets("Output Page").Select
ActiveSheet.Unprotect Password:="yourpassword"

Then I password protect the sheets again:

Sheets("Raw Data").Select
ActiveSheet.Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True, Password:="yourpassword"
Sheets("Output Page").Select
ActiveSheet.Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True, Password:="yourpassword"

Make sure you also password protect the code.

jill
-----Original Message-----
Hi,

Is it possible to protect/unprotect a sheet with a
password in VBA?. Example please if any.

Thanks
PeteD
.


Tim[_25_]

Protecting Sheets
 
Yes you can. Here is sample code. This uses the active
sheet but you can do a select of any sheet also.

Sub ProtectWorksheet()
ActiveSheet.Protect password:="password"
End Sub

Sub UnprotectWorksheet()
ActiveSheet.Unprotect password:="password"
End Sub

-----Original Message-----
Hi,

Is it possible to protect/unprotect a sheet with a
password in VBA?. Example please if any.

Thanks
PeteD
.




PeteD

Protecting Sheets
 
Thanks Jill

PeteD


-----Original Message-----
Pete,

Here is a sample that I use.
At the start of the code I unprotect the sheets so the
rest of my code can run:

Sheets("Raw Data").Select
ActiveSheet.Unprotect Password:="yourpassword"
Sheets("Output Page").Select
ActiveSheet.Unprotect Password:="yourpassword"

Then I password protect the sheets again:

Sheets("Raw Data").Select
ActiveSheet.Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True, Password:="yourpassword"
Sheets("Output Page").Select
ActiveSheet.Protect DrawingObjects:=True,
Contents:=True, Scenarios:=True, Password:="yourpassword"

Make sure you also password protect the code.

jill
-----Original Message-----
Hi,

Is it possible to protect/unprotect a sheet with a
password in VBA?. Example please if any.

Thanks
PeteD
.

.


PeteD

Protecting Sheets
 
Thanks Tim.

Pete



-----Original Message-----
Yes you can. Here is sample code. This uses the active
sheet but you can do a select of any sheet also.

Sub ProtectWorksheet()
ActiveSheet.Protect password:="password"
End Sub

Sub UnprotectWorksheet()
ActiveSheet.Unprotect password:="password"
End Sub

-----Original Message-----
Hi,

Is it possible to protect/unprotect a sheet with a
password in VBA?. Example please if any.

Thanks
PeteD
.



.



All times are GMT +1. The time now is 08:09 AM.

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