Gruppe
Grafik
Problem
Beim Öffnen der Arbeitsmappe soll eine Symbolleiste erstellt und beim Schließen wieder gelöscht werden. Die Symbolleistenschaltflächen sollen nach den Einträgen in Spalte A benannt werden. Änderungen werden übernommen.
ClassModule: DieseArbeitsmappe
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.CommandBars("MyCellBar").Delete
On Error GoTo 0
End Sub
Private Sub Workbook_Open()
Dim oBar As CommandBar
Dim oBtn As CommandBarButton
Dim iCounter As Integer
On Error Resume Next
Application.CommandBars("MyCellBar").Delete
On Error GoTo 0
Set oBar = Application.CommandBars.Add("MyCellBar", msoBarTop, False, True)
iCounter = 1
Do Until IsEmpty(Cells(iCounter, 1))
Set oBtn = oBar.Controls.Add
With oBtn
.Caption = Cells(iCounter, 1).Value
.OnAction = "CntrMsg"
.Style = msoButtonCaption
End With
iCounter = iCounter + 1
Loop
oBar.Visible = True
End Sub
ClassModule: Tabelle1
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("A1").CurrentRegion) _
Is Nothing Then Exit Sub
Application.CommandBars("MyCellBar") _
.Controls(Target.Row).Caption = Target.Value
End Sub