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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Protected Workbook keeps asking for password

Status
Not open for further replies.

jh3016

Programmer
Jun 6, 2003
148
US
I have a master workbook that hyperlinks to another workbook that has several worksheets. The master hyperlink has the months of the years which link to another worksheet that has the months as tabs.

I pointed the hyperlinks in the master document to the bookmarks for the appropriate months.

The problem I am encountering is in the workbook that is being linked to. I have password-protected this document. When I'm in the master workbook and click on the hyperlink to go to the other workbook, it always prompts me for the password even though the workbook is already open.

I'm using Excel XP.

What am I missing?

Help!

Thanks in advance.
 
You must unprotect the file that's already open. Here's some code that might help.

Protecting / Unprotecting a sheet [27/10/2001]
The macros below will protect/unprotect the current worksheet with a password.
Sub ProtectSheet()
Dim Password 'This line of code is optional
Password = "1234"
ActiveSheet.Protect Password, True, True, True
End Sub
Sub UnProtectSheet()
Password = "1234"
ActiveSheet.Unprotect Password
End Sub

Protecting all sheets [27/10/2001] (back to top)
To protect all the sheets this macro uses all the methods contained in this page (see counting sheets). The If, Then statement is also used here. This tests for a condition and if the condition is TRUE, then the macro continuous the next line of code. In this case it will END the macro. If the condition is NOT TRUE, then it will go to the following line which in this case is to select the next sheet. You will also notice the For, Next statement is also used. This acts as a counter to tell the macro how many loops to run. In this case if there are 3 sheets, the macro will run 3 times protecting all the 3 sheets.
Sub protectAll()
Dim myCount 'This line of code is optional
Dim i 'This line of code is optional
myCount = Application.Sheets.Count
Sheets(1).Select 'This line of code selects the 1st sheet
For i = 1 To myCount
ActiveSheet.Protect
If i = myCount Then
End
End If
ActiveSheet.Next.Select
Next i
End Sub

Protecting your VB code [10/3/2002]
To protect your VB code from being seen by others, all you need to do is go to the project explorer, point at your project and right click on it. Select VBA project properties, click on the protection tab and check the Lock project for viewing and key your password. That's it.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top