Gruppe
Ereignis
Problem
Wie kann ich mir bei Doppelklick auf eine Zelle ein Kontextmenü mit Einträgen aus einer Liste einer zweiten Tabelle anzeigen lassen? Das ausgewählte Element soll in die Zelle eingetragen und die Anzahl der in einer Zeile vorhandenen Elemente soll in der zweiten Tabelle gezählt werden.
ClassModule: DieseArbeitsmappe
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call DeleteCmdBar
End Sub
ClassModule: Tabelle1
Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Excel.Range, Cancel As Boolean)
Dim oBar As CommandBar
Dim oBtn As CommandBarButton
Dim wks As Worksheet
Dim iCol As Integer
Cancel = True
Set wks = Worksheets("Daten")
Call DeleteCmdBar
Set oBar = Application.CommandBars.Add( _
Name:="StringInsert", _
Position:=msoBarPopup, _
MenuBar:=False, _
temporary:=True)
iCol = 1
Do Until IsEmpty(wks.Cells(1, iCol))
Set oBtn = oBar.Controls.Add
With oBtn
.Caption = wks.Cells(1, iCol).Value
.Style = msoButtonCaption
.OnAction = "GetValue"
End With
iCol = iCol + 1
Loop
CommandBars("StringInsert").ShowPopup
End Sub
StandardModule: basMain
Sub GetValue()
ActiveCell.Value = _
Application.CommandBars("StringInsert") _
.Controls(Application.Caller(1)).Caption
End Sub
Sub DeleteCmdBar()
On Error Resume Next
Application.CommandBars("StringInsert").Delete
On Error GoTo 0
End Sub