Ken was telling us:
Ken nous racontait que :
Using VBA code, how can I generate a list of macros, preferably with
the module name that they reside in.
First, you will need to set a reference to "Microsoft Visual Basic for
Applications Extensibility 5.3" from Tools > References in the VBA editor
window.
Second, from the main Word windows, make sure you check the "Trust access to
Visual Basic Project" from Tools > Macros > Security > "Trusted Publishers"
tab.
Then, you can try this:
Sub MacroList()
Dim vbCurrent As VBProject
Dim strProject As String
Dim strSub As String
Dim i As Long
Dim j As Long
Dim k As Long
Dim lngLineCount As Long
Set vbCurrent = ActiveDocument.VBProject
strProject = "The project Name is: " & vbCurrent.Name & "." _
& vbCrLf
With vbCurrent
For i = 1 To .VBComponents.Count
strProject = strProject & vbTab & "Module " & i & " is: " _
& .VBComponents(i).Name & vbCrLf
lngLineCount = .VBComponents(i).CodeModule.CountOfLines
If lngLineCount > 3 Then
j = 1
k = 1
Do While strSub = ""
strSub = .VBComponents(i).CodeModule _
.ProcOfLine(j, vbext_pk_Proc)
j = j + 1
Loop
strProject = strProject & vbTab & vbTab & _
"The procedure(s) in this module are:" & vbCrLf
strProject = strProject & vbTab & vbTab & vbTab & _
"Procedure " & k & ": " & strSub & vbCrLf
For j = j To lngLineCount
If .VBComponents(i).CodeModule _
.ProcOfLine(j, vbext_pk_Proc) <> strSub Then
k = k + 1
strSub = .VBComponents(i).CodeModule _
.ProcOfLine(j, vbext_pk_Proc)
strProject = strProject & vbTab & vbTab & vbTab _
& "Procedure " & k & ": " & strSub & vbCrLf
End If
Next
Else
strProject = strProject & vbTab & vbTab & _
"No macro in this module." & vbCrLf
End If
Next
End With
Selection.TypeText strProject
End Sub