ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro for unprotecting/protecting worksheets WITH passwords (https://www.excelbanter.com/excel-programming/303424-macro-unprotecting-protecting-worksheets-passwords.html)

John Baker

Macro for unprotecting/protecting worksheets WITH passwords
 
Hi:

I am developing a macro which will copy data from one workbook to another. Both workbooks
are password protected.

I need to have a macro that will un protect the worksheet and then another that will re
protect it with the same password. Its OK if the system knows the password.

"ActiveSheet.Unprotect" works fine IF there is no password, but if there is one it asks
for it, and that's what I don't want. The same is true of

ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True


adding Password="xxx" does not work, and somehow the help file doesn't help either.

Can someone give me the magic words that will make this function.

Thanks

John Baker


keepITcool

Macro for unprotecting/protecting worksheets WITH passwords
 
adding Password:="lockIT" does work.. note the syntax of a named
parameter..

Sub Macro1()

If ActiveSheet.ProtectContents Then
ActiveSheet.Unprotect Password:="lockIT"
Else
ActiveSheet.Protect Contents:=True, Password:="lockIT"
End If
MsgBox "Protection = " & IIf(ActiveSheet.ProtectContents, "ENabled",
"DISabled")
End Sub




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


John Baker wrote:

ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True


adding Password="xxx" does not work, and somehow the help file doesn't
help either.



John Baker

Macro for unprotecting/protecting worksheets WITH passwords
 
Thank you.

Its the syntax that always gets me -- there are such variations between programming
methods and applications that I get muddled.

Thanks again

John
keepITcool wrote:

adding Password:="lockIT" does work.. note the syntax of a named
parameter..

Sub Macro1()

If ActiveSheet.ProtectContents Then
ActiveSheet.Unprotect Password:="lockIT"
Else
ActiveSheet.Protect Contents:=True, Password:="lockIT"
End If
MsgBox "Protection = " & IIf(ActiveSheet.ProtectContents, "ENabled",
"DISabled")
End Sub




keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


John Baker wrote:

ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True


adding Password="xxx" does not work, and somehow the help file doesn't
help either.




All times are GMT +1. The time now is 06:41 AM.

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