Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to list all procedure names from all modules in Word document

Status
Not open for further replies.

Jtorres13

Technical User
Nov 11, 2006
162
US
How to list all procedure names from all modules in Word document?

Hello. I have searched up and down the forums and found how to list all procedure names from an Excel Workbook. I don't know how to modify it to work in Word. I'm not very good at VBA. Can someone help?
 
It should be similar to what you found for Excel since it is using the VBA object model itself. Post what you found for Excel.

Gerry
 
It should be something like (but of course it could be different!):
Code:
Sub ListProcedures()
Dim currProj As VBIDE.VBProject
Dim allComps As VBIDE.VBComponents
Dim myMod As VBIDE.VBComponent
Dim j As Long
Dim EachLine As String
Dim var
Dim ProcedureNames As String


Set currProj = ActiveDocument.VBProject
Set allComps = currProj.VBComponents
For Each myMod In allComps
      j = myMod.CodeModule.CountOfLines
      ProcedureNames = ProcedureNames & vbCrLf & _
            "Module: " & myMod.Name & vbCrLf
      
      For var = 1 To j
         EachLine = myMod.CodeModule.Lines(var, 1)
         If InStr(1, EachLine, "Sub") > 0 _
            And InStr(1, EachLine, "End Sub") = 0 Then
            ProcedureNames = ProcedureNames & EachLine & vbCrLf
         End If
      Next
Next
      MsgBox ProcedureNames
End Sub

So say you have:

Module: ThisDocument
Sub AProcedureInThisDocument

Module: modOne
Sub modOne_ProcOne
Sub modOne_ProcTwo
Sub modOne_ProcThree

Module: modTwo
Sub modTwo_ProcOne
Sub modTwo_ProcTwo
Sub modTwo_ProcThree

You end up with:


Moduel: ThisDocument
Sub AProcedureInThisDocument

Module: modOne
Sub modOne_ProcOne
Sub modOne_ProcTwo
Sub modOne_ProcThree

Module: modTwo
Sub modTwo_ProcOne
Sub modTwo_ProcTwo
Sub modTwo_ProcThree

Gerry
 
Although I forgot to include the "()" - or included paramters in the listing. So it could be:

Sub modTwo_Proc(strIn As String)

You could of course do more string processing for EachLine to get that down to:

modTwo_ProcTwo

Depends on what results you want.

Gerry
 
Ah, I bet you were looking at Pearson's VBA stuff. It is probably better as it uses

ProcKindString(ProcKind As VBIDE.vbext_ProcKind)

Gerry
 
I can't remember where I found the one for Excel. I thank you for the reply. I will try it. Sorry to say I had to do it manually, as I was on a deadline. But,nonetheless, now I have an answer in my threads so I will go back and try it anyways. Thanks again. I will post changes I do, if any.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top