In vba, how can i call a word document and get a list of all the macros it contains?
This article should show you how to do it (it's for Word 2000 but I assume there's a good chance it'll work for whatever version you use): WD2000: Sample Macro to Return Macro and Procedure Names
This is the code from that article:
Sub ListAllMacroNames()
Dim pj As VBProject
Dim vbcomp As VBComponent
Dim curMacro As String, newMacro As String
Dim x As String
Dim y As String
On Error Resume Next
curMacro = ""
Documents.Add
For Each pj In Application.VBE.VBProjects
x = pj.FileName
y = pj.Protection
If x <> "" Then
If y <> "1" Then
Selection.InsertAfter "The " & Chr(34) & x & Chr(34) & _
" project contains " & "the following macro names:" & vbCr
Selection.InsertAfter vbCr
For Each vbcomp In pj.VBComponents
For i = 1 To vbcomp.CodeModule.CountOfLines
newMacro = vbcomp.CodeModule.ProcOfLine(Line:=i, _
prockind:=vbext_pk_Proc)
If curMacro <> newMacro Then
curMacro = newMacro
If curMacro <> "" And curMacro <> "app_NewDocument" Then
Selection.InsertAfter newMacro & vbCr
Selection.Collapse wdCollapseEnd
End If
End If
Next
Next
Else
Selection.InsertAfter "The project " & Chr(34) & x & Chr(34) & _
" is locked. " & "Macros in this locked project will not be" _
& " listed." & vbCr & vbCr
End If
Selection.InsertAfter vbCr
End If
x = ""
Next
Selection.Collapse wdCollapseEnd
End Sub