LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 395
Default Syntax to match sheet by codename

I'm attempting to show/hide sheets via code, so I can see all the sheets when
updating a workbook, then hide the source sheets so my users just see the
output sheets.

unhiding every sheet is easy;
Sub ShowAllSheets()
Dim sht As Worksheet
For Each sht In Excel.ActiveWorkbook.Worksheets
sht.Visible = xlSheetVisible
Next
End Sub

But when trying to re-hide, I need to exclude the user sheets. I know how to
do this by setting up an array of every sheet to be hidden, but that is a lot
of extra code. Here is my attempt to hide everything except three user sheets
(I've tried several variations) with no luck. I keep getting a 438 runtime
error, "object does not support this property or method"

Sub HideAllSheets()
Dim sht As Worksheet

Dim shta As Worksheet
Dim shtb As Worksheet
Dim shtc As Worksheet

Set shta = Sheet2
Set shtb = Sheet4
Set shtc = Sheet17

For Each sht In Excel.ActiveWorkbook.Worksheets
If (sht = shta) Or (sht = shtb) Or (sht = shtc) Then '<--- this is
where it fails
'do nothing
Else
sht.Visible = xlSheetHidden
End If
Next
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting Sheet By Codename Kris_Wright_77 Excel Programming 4 December 16th 09 04:23 PM
Hide sheet via codename [email protected] Excel Programming 3 September 13th 06 08:28 PM
Use of sheet codename in codeline - How? Jim May Excel Programming 3 July 1st 06 04:24 PM
Selecting a sheet by codename Dr.Schwartz Excel Programming 3 September 3rd 04 02:15 PM
Using sheet codename problems Dustin Carter Excel Programming 1 February 20th 04 10:26 PM


All times are GMT +1. The time now is 11:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"