Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password Protecting in a Macro

Status
Not open for further replies.

ALKnapp

Technical User
Mar 3, 2003
5
US
Hello,
Can someone please help me?

I am writing a Macro in Excel using VB 6. This Macro does some basic copy and pasting; however, the worksheet is password protected. The Macro needs to unprotect the sheet, copy & paste, and then re-protect the sheet with a password. I created a simplified example to attempt to get this Macro to work and am not having any luck. The error, "The password you supplied is not correct. Verify that the CAPS LOCK key is off and be sure to use the correct capitalization" keeps appearing. The password in the code is the correct password.

Here is my sample code:
Sub PROTECTION()
ActiveSheet.Unprotect (at)
Range("A1:A3").Select
Selection.Copy
Range("A5").Select
ActiveSheet.Paste
Application.CutCopyMode = False
ActiveSheet.Protect (at), DrawingObjects:=True, Contents:=True, Scenarios:=True
Range("B12").Select
End Sub

Please advise... I will greatly appreciate the help. Thanks.
 
Try quotes around the password
ActiveSheet.Unprotect ("at")
 
I use a similar sub routine and do not put any brackets arround the password, so if my password were 111 the code would be
ActiveSheet.Unprotect 111

this definately works for me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top