ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using Activebook.Unprotect in macro giving errors (Password) (https://www.excelbanter.com/excel-programming/438374-using-activebook-unprotect-macro-giving-errors-password.html)

Bricol

Using Activebook.Unprotect in macro giving errors (Password)
 
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 Structu=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) ]

Per Jessen[_2_]

Using Activebook.Unprotect in macro giving errors (Password)
 
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



On 13 Jan., 17:06, Bricol wrote:
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 Structu=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) ]




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

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