ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Password protecting sheets through VBA (https://www.excelbanter.com/excel-programming/341161-password-protecting-sheets-through-vba.html)

Eithne R[_2_]

Password protecting sheets through VBA
 
I want to password protect a spreadsheet / sheets but need to be able to
unprotect them to manipulate them via a macro. Is this possible? The
password option does not appear to be available in the protect method. Cheers

Chip Pearson

Password protecting sheets through VBA
 
Use the UserInterfaceOnly flag of the Protect method. This
prevents the user from modifying the sheet, but allows VBA to do
anything. This property is not saved with the workbook, so you
should protect the sheet(s) in the Workbook_Open event. E.g.,


Private Sub Workbook_Open()
Worksheets("Sheet1").Protect Password:="abc",
userinterfaceonly:=True
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Eithne R" wrote in message
...
I want to password protect a spreadsheet / sheets but need to be
able to
unprotect them to manipulate them via a macro. Is this
possible? The
password option does not appear to be available in the protect
method. Cheers




Ron de Bruin

Password protecting sheets through VBA
 
Yes it is available

ActiveSheet.Protect Password:="Ron"

ActiveSheet.Unprotect Password:="Ron"


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Eithne R" wrote in message ...
I want to password protect a spreadsheet / sheets but need to be able to
unprotect them to manipulate them via a macro. Is this possible? The
password option does not appear to be available in the protect method. Cheers





All times are GMT +1. The time now is 02:30 PM.

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