Hi All.
I have code which creates a tool bar which works Ok, however I can't get the statement correct to assign code to it.
Option Explicit
Public Const ToolBarName As String = "Unhide All Sheets"
'===========================================
Sub Auto_Open()
Call CreateMenubar
End Sub
'===========================================
Sub Auto_Close()
Call RemoveMenubar
End Sub
'===========================================
Sub RemoveMenubar()
On Error Resume Next
Application.CommandBars(ToolBarName).Delete
On Error GoTo 0
End Sub
'===========================================
Sub CreateMenubar()
Dim iCtr As Long
Dim MacNames As Variant
Dim CapNamess As Variant
Dim TipText As Variant
Call RemoveMenubar
MacNames = Array("UnhideAll", _
"RehideAll")
CapNamess = Array("UnhideAll", _
"RehideAll")
TipText = Array("UnhideAll", _
"RehideAll")
With Application.CommandBars.Add
.Name = ToolBarName
.Left = 200
.Top = 200
.Protection = msoBarNoProtection
.Visible = True
.Position = msoBarTop
For iCtr = LBound(MacNames) To UBound(MacNames)
With .Controls.Add(Type:=msoControlButton)
.OnAction = "'" & ThisWorkbook.Name & "'!" & MacNames(iCtr)
.Caption = CapNamess(iCtr)
.Style = msoButtonIconAndCaption
.FaceId = 2308 + iCtr
.TooltipText = TipText(iCtr)
End With
Next iCtr
End With
End Sub
This is the code that I want to assign to the toolbar:
Private SheetHideUnhide() As Boolean
Sub UnhideAll()
Application.ScreenUpdating = False
Dim sh As Worksheet
Dim intNoSh As Integer
Dim i As Integer
intNoSh = Application.Sheets.Count
i = 1
ReDim SheetHideUnhide(1 To intNoSh)
For Each sh In Worksheets
SheetHideUnhide(i) = sh.Visible
sh.Visible = True
i = i + 1
Next
End Sub
Sub RehideAll()
Application.ScreenUpdating = False
Dim sh As Worksheet
Dim intNoSh As Integer
Dim i As Integer
intNoSh = Application.Sheets.Count
i = 1
For Each sh In Worksheets
sh.Visible = SheetHideUnhide(i)
i = i + 1
Next
End Sub
All help welcomed!
Thanks
Simon
Bookmarks