View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bricol Bricol is offline
external usenet poster
 
Posts: 10
Default Activebook.Unprotect in macro giving errors (Pwd)#2

(Sorry if duplicated but network went down 1st time)

I have two pieces of code in workbook & cant see what I am doing wrong.

The first (seems to work) should hide a specific sheet & then protect the
workbook to stop unauthorised users from viewing

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 PASSWORD to unprotect the workbook &
display the hidden sheet, but keeps aborting..

Sub Show()
'
ActiveWorkbook.Unprotect

Sheets(2).Visible = True

End Sub

Everytime I try to run it aborts and gives
"Run-time error '1004':
The password supplied is incorrect......"

(BUT I HAVEN'T EVEN BEEN PROMPTED FOR A PASSWORD!?)
What am I doing wrong? Thanks

Using Excel 2007, but wb is 2003 Compatible)