Please help me find veryhidden sheets

J

J.W. Aldridge

Hi.
I found a code that works fine when hiding my sheets, but when I try
to unhide them, I cant get anywhere.I get the following code:

Runtime error 1004. Unable to set the property of the worksheet class

Anything wrong with my code?
Please help.


Sub unHideModeratelyWell2()
Dim shArray As Variant
Dim i As Long
shArray = Array("INFO SHEET", "ROSTER", "TIMESHEET",
"PRODUCTION")
For i = LBound(shArray) To UBound(shArray)
With Sheets(shArray(i))
.Unprotect Password:="pcp123"
.Visible = xlSheetVisible
End With
Next
End Sub
///////////////////////////////////////////////
The code I used to hide them was:
//////////////////////////////////////////////
Sub HideModeratelyWell2()
Dim shArray As Variant
Dim i As Long
shArray = Array("INFO SHEET", "ROSTER", "TIMESHEET",
"PRODUCTION")
For i = LBound(shArray) To UBound(shArray)
With Sheets(shArray(i))
.Protect Password:="pcp123"
.Visible = xlVeryHidden
End With
Next
End Sub
 
G

Guest

Hi,

Your error is attempting to select the hidden sheets in the following code:-
shArray = Array("INFO SHEET", "ROSTER", "TIMESHEET", "PRODUCTION")

You can't select hidden sheets.

The following is untested but you need to something like it and include the
password etc:-

For Each ws In Worksheets
If ws.Name = "INFO SHEET" Or ws.Name ="TIMESHEET" _
Or ws.Name="PRODUCTION" Then
ws.Visible = True
End If
Next ws

Regards,

OssieMac
 
D

Dave Peterson

Is your workbook protected?



J.W. Aldridge said:
Hi.
I found a code that works fine when hiding my sheets, but when I try
to unhide them, I cant get anywhere.I get the following code:

Runtime error 1004. Unable to set the property of the worksheet class

Anything wrong with my code?
Please help.

Sub unHideModeratelyWell2()
Dim shArray As Variant
Dim i As Long
shArray = Array("INFO SHEET", "ROSTER", "TIMESHEET",
"PRODUCTION")
For i = LBound(shArray) To UBound(shArray)
With Sheets(shArray(i))
.Unprotect Password:="pcp123"
.Visible = xlSheetVisible
End With
Next
End Sub
///////////////////////////////////////////////
The code I used to hide them was:
//////////////////////////////////////////////
Sub HideModeratelyWell2()
Dim shArray As Variant
Dim i As Long
shArray = Array("INFO SHEET", "ROSTER", "TIMESHEET",
"PRODUCTION")
For i = LBound(shArray) To UBound(shArray)
With Sheets(shArray(i))
.Protect Password:="pcp123"
.Visible = xlVeryHidden
End With
Next
End Sub
 
D

Dave Peterson

ps. Your code worked fine in my simple test when I created a new workbook and
added worksheets with those names.
 
J

J.W. Aldridge

Thank you ALL for your assistance....

Dave, You hit it on the head. My workbook was protected.
Once I unprotected it, it worked just fine!

Thanx....

When I get my first million...
You got a Krystal Burger on me! (That's with cheese!)

LOL (thanx!)
 

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

Top