Gruppe
Menue
Problem
Wie kann ich beim Öffnen einer Arbeitsmappe eine Symbolleiste mit einer CommandBarComboBox erstellen und mit den Werten aus Spalte A einer Tabelle bestücken? Es handelt sich bei Dateinamen. Bei Auswahl einer Datei in der ComboBox soll diese geöffnet werden.
ClassModule: DieseArbeitsmappe
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call CmdDelete
End Sub
Private Sub Workbook_Open()
Dim wks As Worksheet
Dim oBar As CommandBar
Dim oCbo As CommandBarComboBox
Dim iCounter As Integer
Set wks = ThisWorkbook.Worksheets("Tabelle1")
Call CmdDelete
Set oBar = Application.CommandBars.Add("Dateien", msoBarTop)
Set oCbo = oBar.Controls.Add(msoControlComboBox)
iCounter = 1
With oCbo
Do Until IsEmpty(wks.Cells(iCounter, 1))
.AddItem wks.Cells(iCounter, 1).Value
iCounter = iCounter + 1
Loop
.OnAction = "DateienLaden"
.ListIndex = 1
End With
oBar.Visible = True
End Sub
StandardModule: basMain
Sub DateienLaden()
Dim wkb As Workbook
Dim sFile
With CommandBars("Dateien").Controls(1)
sFile = .List(.ListIndex)
End With
On Error Resume Next
Set wkb = Workbooks(sFile)
If Err > 0 Or wkb Is Nothing Then
Err.Clear
On Error GoTo 0
Workbooks.Open (sFile)
End If
End Sub
Sub CmdDelete()
On Error GoTo ERRORHANDLER
Application.CommandBars("Dateien").Delete
ERRORHANDLER:
End Sub