Hi,
here is a sample for adding your own CommandBar with one -Button. To get
the button click event you need to declare a variable WithEvents
Private WihEvents YourButton as Office.CommandBarButton
Private Application_Startup()
Set YourButton=CreateCommandBarButton(Application.ActiveExplorer _
.CommandBars)
End Sub
Private Sub YourButton_Click(ByVal Ctrl As Office.CommandBarButton,
CancelDefault As Boolean)
' here your code goes
End Sub
Private Function CreateCommandBarButton(oBars As Office.CommandBars) As
Office.CommandBarButton
On Error Resume Next
Dim oMenu As Office.CommandBar
Dim oBtn As Office.CommandBarButton
Const BAR_NAME As String = "YourCommandBarName"
Const CMD_NAME As String = "YourButtonName"
Set oMenu = oBars(BAR_NAME)
If oMenu Is Nothing Then
Set oMenu = oBars.Add(BAR_NAME, msoBarTop, , True)
Set oBtn = oMenu.Controls.Add(msoControlButton, , CMD_NAME, , True)
oBtn.Caption = CMD_NAME
oBtn.Tag = CMD_NAME
Else
Set oBtn = oMenu.FindControl(, , CMD_NAME)
If oBtn Is Nothing Then
Set oBtn = oMenu.Controls.Add(msoControlButton, , CMD_NAME, ,
True)
End If
End If
oMenu.Visible = True
Set CreateCommandBarButton = oBtn
End Function