Ich möchte alle Makros in einer ComboBox auflisten. Ich will ein bestimmtes Makro aus der Liste auswählen und seinen Namen in einer Stringvariable speichern können.
Kann mir jemand sagen wie ich das machen könnte?
Grüsse Matthias
Private Sub Makroliste()
Dim vbc As Object, sh As Worksheet
Dim iRow As Integer, iCol As Integer, iCounter As Integer
Set sh = ActiveWorkbook.Sheets(1)
sh.Cells.Clear
iRow = 1
iCol = 1
For Each vbc In ActiveWorkbook.VBProject.VBComponents
With vbc.CodeModule
For iCounter = 1 To .CountOfLines
If .ProcOfLine(iCounter, 0) > "" Then
If Trim(.Lines(iCounter, 1)) Like "Sub *" Then
sh.Cells(iRow, iCol).Value = .ProcOfLine(iCounter, 0)
iRow = iRow + 1
End If
End If
Next iCounter
End With
Next vbc
sh.Range("A1").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
sh.Columns.AutoFit
End Sub