Using Activebook.Unprotect in macro giving errors (Password)

B

Bricol

I have scoured net for answer without success, & hope someone here can help.

I have two procedures in my file
The first Hides a specific sheet & then protects the workbook WITH A
PASSWORD to prevent user from displaying - seems to work fine...

Sub Hide()
On Error Resume Next
Sheets(2).Select
ActiveWindow.SelectedSheets.Visible = False
ActiveWorkbook.Protect Structure:=True, Windows:=False,
Password:="Mypassword"
End Sub

The 2nd should allow a user who has the password to unprotect & view the
sheet, but it doesnt work!

Sub Show()
'
ActiveWorkbook.Unprotect

Sheets(2).Visible = True

End Sub

Every time I try & run 2nd macro it stops with a
"Run-time error '1004':
The password you supplied is not correct....."
BUT IT ISN'T PROMPTING ME TO SUPPLY A PASSWORD!?

What am I doing wrong?

[Using Excel 2007 (but workbook is 2003 Compatible) ]
 
P

Per Jessen

Hi

You need to insert the password in the unprotect statement:

Sub Show()
'
ActiveWorkbook.Unprotect Password:="Mypassword"

Sheets(2).Visible = True

End Sub

Regards,
Per
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top