Hi,
I have the following code
how can i amend it to automatically update the toolbar with all the sheets in the toolbar, isntead of having to click on "Referesh Worksheet list"![]()
Sub Auto_Close() On Error Resume Next Application.CommandBars("Daily Backlog/Inflow Navigation Toolbar").Delete On Error GoTo 0 End Sub Sub Auto_Open() 'code written by Pratik Dhody Dim cb As CommandBar Dim ctrl As CommandBarControl On Error Resume Next Application.CommandBars("Daily Backlog/Inflow Navigation Toolbar").Delete On Error GoTo 0 Set cb = Application.CommandBars.Add(Name:="Daily Backlog/Inflow Navigation Toolbar", temporary:=True) With cb .Visible = True Set ctrl = .Controls.Add(Type:=msoControlButton, temporary:=True) With ctrl .Style = msoButtonCaption .Caption = "Refresh Worksheet List" .OnAction = ThisWorkbook.Name & "!refreshthesheets" End With Set ctrl = .Controls.Add(Type:=msoControlComboBox, temporary:=True) With ctrl .Width = 300 .AddItem "Click Refresh First" .OnAction = ThisWorkbook.Name & "!changethesheet" .Tag = "__wksnames__" End With End With End Sub Sub ChangeTheSheet() Dim myWksName As String Dim wks With Application.CommandBars.ActionControl If .ListIndex = 0 Then MsgBox "Please select an existing sheet" Exit Sub Else myWksName = .List(.ListIndex) End If End With Set wks = Nothing On Error Resume Next Set wks = Sheets(myWksName) On Error GoTo 0 If wks Is Nothing Then Call RefreshTheSheets MsgBox "Please try again" Else wks.Select End If End Sub Sub RefreshTheSheets() Dim ctrl As CommandBarControl Dim wks Set ctrl = Application.CommandBars("Daily Backlog/Inflow Navigation Toolbar") _ .FindControl(Tag:="__wksnames__") ctrl.Clear For Each wks In ActiveWorkbook.Sheets If wks.Visible = xlSheetVisible Then ctrl.AddItem wks.Name End If Next wks End Sub
cheers
Bookmarks