Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Toggle sheet visibility

How can I modify the below code to remember what sheets were
originally hidden so that it only hides those sheets? Kind of like a
"smart" toggle current hidden sheets.

For Each sh In Sheets
sh.Visible = True
Next sh

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Toggle sheet visibility

Try something like the following. Run LoadHiddenValues when you want to save
the sheet's visible properties and ShowOrHide when you want to restore the
saved visible properties.

Sub LoadHiddenValues()
Dim N As Long
Dim S As String
With ThisWorkbook.Sheets ' Sheets not Worksheets
For N = 1 To .Count
S = S & .Item(N).Name & ":" & CStr(.Item(N).Visible) & "\"
Next N
End With
S = Left(S, Len(S) - 1)
ThisWorkbook.Names.Add Name:="SheetVisible", RefersTo:="'" & S & "'",
Visible:=False
End Sub

Sub ShowOrHide()
Dim S As String
Dim V As Variant
Dim W As Variant
Dim N As Long

Application.ScreenUpdating = False
S = ThisWorkbook.Names("SheetVisible").RefersTo
S = Replace(S, Chr(34), "")
S = Replace(S, Chr(39), "")
S = Mid(S, 2)
V = Split(S, "\")
With ThisWorkbook.Sheets
For N = 1 To UBound(V)
W = Split(V(N), ":")
.Item(W(0)).Visible = W(1)
Next N
W = Split(V(0), ":")
.Item(W(0)).Visible = W(1)
End With
ErrH:
Application.ScreenUpdating = True
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"John" wrote in message
s.com...
How can I modify the below code to remember what sheets were
originally hidden so that it only hides those sheets? Kind of like a
"smart" toggle current hidden sheets.

For Each sh In Sheets
sh.Visible = True
Next sh


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Toggle sheet visibility

Thanks, Chip! That gives me something to chew on...


On Oct 8, 4:14 pm, "Chip Pearson" wrote:
Try something like the following. Run LoadHiddenValues when you want to save
the sheet's visible properties and ShowOrHide when you want to restore the
saved visible properties.

Sub LoadHiddenValues()
Dim N As Long
Dim S As String
With ThisWorkbook.Sheets ' Sheets not Worksheets
For N = 1 To .Count
S = S & .Item(N).Name & ":" & CStr(.Item(N).Visible) & "\"
Next N
End With
S = Left(S, Len(S) - 1)
ThisWorkbook.Names.Add Name:="SheetVisible", RefersTo:="'" & S & "'",
Visible:=False
End Sub

Sub ShowOrHide()
Dim S As String
Dim V As Variant
Dim W As Variant
Dim N As Long

Application.ScreenUpdating = False
S = ThisWorkbook.Names("SheetVisible").RefersTo
S = Replace(S, Chr(34), "")
S = Replace(S, Chr(39), "")
S = Mid(S, 2)
V = Split(S, "\")
With ThisWorkbook.Sheets
For N = 1 To UBound(V)
W = Split(V(N), ":")
.Item(W(0)).Visible = W(1)
Next N
W = Split(V(0), ":")
.Item(W(0)).Visible = W(1)
End With
ErrH:
Application.ScreenUpdating = True
End Sub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consultingwww.cpearson.com
(email on the web site)

"John" wrote in message

s.com...

How can I modify the below code to remember what sheets were
originally hidden so that it only hides those sheets? Kind of like a
"smart" toggle current hidden sheets.


For Each sh In Sheets
sh.Visible = True
Next sh



Reply
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
Add-In Visibility Trent Argante Excel Discussion (Misc queries) 5 February 13th 08 08:01 PM
HOW CAN I HAVE THE SHEET TO BE PROTECTED, FORMULAS HIDDEN AND YET GIVE AN OPTION IN VB TO HAVE A TOGGLE TO PROTECT/ UNPROTECT/HIDE/UNHIDE CELLS CAPTGNVR Excel Programming 0 February 17th 07 11:13 AM
User controls on sheet question. - How to toggle between design and execute mode? Hexman Excel Programming 1 December 22nd 05 01:06 AM
Toggle between excel sheet and user form Omar Excel Programming 2 March 1st 05 07:11 AM
Excel Timer with Sheet Toggle Help Tysone Excel Programming 6 April 14th 04 07:20 PM


All times are GMT +1. The time now is 11:41 AM.

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

About Us

"It's about Microsoft Excel"