Gruppe
Menue
Problem
Es wird nur dann ein eigenes Zell-Kontextmenü angezeigt, wenn eine oder mehrere Zeilen markiert sind.
ClassModule: Tabelle1
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
Dim oBar As CommandBar
Dim oBtn As CommandBarButton
If Selection.Columns.Count = 256 Then
Cancel = True
On Error GoTo ERRORHANDLER
Set oBar = Application.CommandBars.Add("MyContextBar", msoBarPopup)
Set oBtn = oBar.Controls.Add
With oBtn
.Caption = "Meldung"
.OnAction = "Meldung"
.Style = msoButtonCaption
End With
oBar.ShowPopup
End If
ERRORHANDLER:
On Error Resume Next
Application.CommandBars("MyContextBar").Delete
Resume
End Sub
StandardModule: Modul1
Sub Meldung()
If Selection.Rows.Count = 1 Then
MsgBox "Zeile " & Selection.Address(False, False) & " markiert!"
Else
MsgBox "Zeilen " & Selection.Address(False, False) & " markiert!"
End If
Application.CommandBars("MyContextBar").Delete
End Sub