CommandButton code help

P

peter.thompson

I want to use a common set of 7 commandbuttons as a 'menu bar' on
several worksheets (each commandbutton opens a worksheet instead of
using the standard tabs)

What is the best way to go about this to minimise code?

Any help much appreciated

Cheers

Peter
 
B

Bob Phillips

Peter,

I add a drop-down to the Formatting toolbar, and in ThisWorkbook, I setup up
the toolbar buton and populate it so

Private Workbook_Open()
With Application.CommandBars("Formatting")
With .Controls.Add(Type:=msoControlDropdown, temporary:=True)
.Caption = "SheetGoto"
.OnAction = "GotoSheet"
End With End With
End Sub

Private Sub Workbook_Activate()
Dim i As Long

With Application.CommandBars("Formatting").Controls("SheetGoto")
.Clear
For i = 1 To Wb.Sheets.Count
.AddItem Wb.Sheets(i).Name
Next i
.ListIndex = 1
End With
End Sub

In a standard code module I add this macro to actiavte the sheet

Private Sub GotoSheet()
With Application.CommandBars.ActionControl
ActiveWorkbook.Sheets(.Text).Activate
End With
End Sub

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"peter.thompson"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top