Gruppe
Menue
Problem
Wie kann ich dem Kontextmenü in der Entwicklungsumgebung einen Menüpunkt hinzufügen und diesem eine Ereignisprozedur zuweisen?
ClassModule: DieseArbeitsmappe
Dim mclsAddMenu As New clsAddMenu
Private Sub Workbook_Open()
Call Zurueck
mclsAddMenu.AddMenuItem
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set mclsAddMenu = Nothing
Call Zurueck
End Sub
StandardModule: basMain
Sub Zurueck()
On Error Resume Next
Application.VBE.CommandBars("Code Window") _
.Controls("Meldung").Delete
On Error GoTo 0
End Sub
ClassModule: clsAddMenu
Public WithEvents Meldung As VBIDE.CommandBarEvents
Public Sub AddMenuItem()
Dim ctlTopMenu As CommandBarButton
Set ctlTopMenu = Application.VBE.CommandBars("Code Window") _
.Controls.Add(Type:=msoControlButton)
ctlTopMenu.Caption = "Meldung"
ctlTopMenu.Enabled = True
Set Meldung = Application.VBE.Events.CommandBarEvents(ctlTopMenu)
End Sub
Private Sub Meldung_Click( _
ByVal cmdBar As Object, handled As Boolean, Cancel As Boolean)
MsgBox "Hallo Welt!"
End Sub