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

unprotect sheet + make visible 1

Status
Not open for further replies.

peach255

Programmer
Jan 20, 2003
29
US
I have a worksheet that is hidden. Whenever the checkmark is clicked, which would result in F12="TRUE", then I want it to open this other sheet called "Polymerase". However, the sheet is protected w/ a password, and I do not want it to prompt the user w/ the password.
I have the following code so far:

If Worksheets("Instructions").Range("F12") = True Then
Sheets("Polymerase").unprotect password:="pw"
Sheets("Polymerase").Visible = True
Sheets("Polymerase").Select
Else
Sheets("Polymerase").Visible = False
End If

And I get a " Run-time error '1004' Unable to set the Visible property of the Worksheet class. "

Thank you!
 
Hello peach

the command for the visible property actually takes in 'worksheets' not 'sheets'.
so the code you need is
Code:
If Worksheets("Instructions").Range("F12") = True Then
    Sheets("Polymerase").unprotect password:="pw"
    Worksheets("Polymerase").Visible = True
    Sheets("Polymerase").Select
Else
    Worksheets("Polymerase").Visible = False
End If

I think that should work :)
 
A better practice would be to name your sheets in the VBE as well (i.e. sPolymerase in the Name Property for that sheet.) That way you wouldn't have to use the "Sheets" or "Worksheets". For example:

Code:
If sInstructions.Range("F12") = True Then
    With Polymerase
        .Unprotect Password:="pw"
        .Visible = True
        .Select
    End With
Else
    sPolymerase.Visible = False 'or xlSheetVeryHidden
End If

The xlSheetVeryHidden stops a user from making a sheet visible by using the FOrmat->Sheet->Unhide feature.

Just a suggestion that might save some time in the future!



If you can't be "The Best", be the best at what you can!!!

Never say Never!!!
Nothing is impossible!!!
 
Bowers74,
I didn't realize you could access sheets directly like that! That is useful. Have a star. (I got doubly excited for a second b/c I thought it might have spawned a shorter solution to the issue I posed in thread707-572825, but after thinking it over, I don't think it does).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top