ich habe ein Add-In mit ein paar Hilfsroutinen.
Jetzt möchte ich im VBA-Editor beim Start des Add-Ins ein Symbol anlegen lassen, das eine der Routinen aufruft. Kann mir jemand aufs Pferd helfen?
Danke.
Stefan.
Sub SymbolLeisteInVBAEin()
' Symbolleiste erstellen
On Error Resume Next
Set symb = Application.VBE.CommandBars.Add("Test", Position:=msoBarTop, Temporary:=True)
With symb
.Left = 0
.Visible = True
End With
Set AA = Application.VBE.CommandBars("Test").Controls.Add(Type:=msoControlButton)
With AA
.Style = msoButtonCaption
.Caption = "Jan"
.BeginGroup = True
.OnAction = "JanEin"
End With
End Sub
Sub SymbolLeisteInVBAAus()
'Symbolleiste löschen
On Error Resume Next
Application.VBE.CommandBars.Add("Test").Delete
End Sub
Sub SymbolLeisteInVBAAus()
On Error Resume Next
Application.VBE.CommandBars("Test").Delete
End Sub
Private Sub Workbook_Open()
Set objMeinMenü = New clsTest
objMeinMenü.Symbolleiste_ein
End Sub
clsTest:
Option Explicit
Public WithEvents objButton1 As CommandBarButton
Public WithEvents objButton2 As CommandBarButton
Public Function Symbolleiste_ein()
Dim cb As CommandBar
Set cb = Application.VBE.CommandBars.Add("TestBar")
cb.Visible = True
cb.Position = msoBarTop
Set objButton1 = cb.Controls.Add(msoControlButton)
With objButton1
.BeginGroup = True
.Style = msoButtonIcon
.TooltipText = "Test Button 1"
.FaceId = 3170
End With
Set objButton2 = cb.Controls.Add(msoControlButton)
With objButton2
.BeginGroup = False
.Style = msoButtonIcon
.TooltipText = "Test Button 2"
.FaceId = 159
End With
End Function
Private Sub objButton1_click(ByVal ctrl As Office.CommandBarButton, CancelDefault As Boolean)
MsgBox "Gedrückt wurde Button 1"
End Sub
Private Sub objButton2_click(ByVal ctrl As Office.CommandBarButton, CancelDefault As Boolean)
MsgBox "Gedrückt wurde Button 2"
End Sub