Results 1 to 9 of 9

Assign code to Toolbar Created in VB to Hide Sheets and then Rehide

Threaded View

  1. #1
    Registered User
    Join Date
    01-14-2009
    Location
    Worcester, England
    MS-Off Ver
    Excel 2007
    Posts
    19

    Assign code to Toolbar Created in VB to Hide Sheets and then Rehide

    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
    Last edited by Simon Austin; 01-23-2009 at 05:06 AM. Reason: Solved

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1