Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default 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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default 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.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Protecting/Unprotecting all sheets with macro leads to "image" iss MikeR Excel Worksheet Functions 3 February 22nd 10 09:33 PM
Protecting and Unprotecting several worksheets at one time Learning Excel Excel Discussion (Misc queries) 8 February 4th 09 10:07 PM
Macro for protecting and unprotecting multiple worksheets saltnsnails Excel Discussion (Misc queries) 7 January 24th 08 10:49 PM
protecting vba code and unprotecting using a vba macro iain Excel Programming 0 June 29th 04 04:59 PM
Protecting & unprotecting worksheets pkley Excel Programming 1 January 7th 04 10:28 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"