Create new commandbar with call procedure

T

Tonmai

Hi,
Anybody pls. kindly give me the sample of coding
that create new commandbar with one commandbarbotton while
opening workbook. This commandbarbotton can call one sub
procedure in program.

Thks for any help.
Tonmai K.
 
J

J.E. McGimpsey

one way:

Call this from the Workbook_Open procedure, i.e.:

Private Sub Workbook_Open()
CreateToolBar
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
DestroyToolBar
End Sub

And in a regular module:

Public Sub CreateToolBar()
On Error Resume Next
CommandBars("Tonmai Bar").Delete
On Error GoTo 0
With CommandBars.Add(Name:="Tonmai Bar", _
Position:=msoBarFloating, Temporary:=True)
.Top = 100
.Left = 500
With .Controls.Add(Type:=msoControlButton)
.FaceId = 2950
.OnAction = "MySub"
End With
.Visible = True
End With
End Sub

Public Sub DestroyToolbar()
On Error Resume Next
CommandBars("Tonmai Bar").Delete
On Error GoTo 0
End Sub
 

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

Top