List all procedures within a module

A

Allen Browne

K said:
Is there a way to list all the procedures within a module?

This kind of thing lists the procedures in a module, and the line where they
start:

Function ListProc(strModuleName As String) As String
Dim mdl As Module
Dim lngCount As Long
Dim lngCountDecl As Long
Dim lngI As Long
Dim strProcName As String
Dim intI As Integer
Dim strMsg As String
Dim lngR As Long

'lngR = vbext_pk_Proc

' Open specified Module object.
DoCmd.OpenModule strModuleName
Set mdl = Modules(strModuleName)

lngCount = mdl.CountOfLines
lngCountDecl = mdl.CountOfDeclarationLines

' Determine name of first procedure.
strProcName = mdl.ProcOfLine(lngCountDecl + 1&, lngR)

intI = 0

Debug.Print strProcName, lngR

' Determine procedure name for each line after declarations.
For lngI = lngCountDecl + 1& To lngCount
' Compare procedure name with ProcOfLine property value.
If strProcName <> mdl.ProcOfLine(lngI, lngR) Then
intI = intI + 1&
strProcName = mdl.ProcOfLine(lngI, lngR)
Debug.Print strProcName
Debug.Print , "ProcStartLine = " &
mdl.ProcStartLine(strProcName, lngR)
Debug.Print , "ProcBodyLine " & mdl.ProcBodyLine(strProcName,
lngR)
'ProcBodyLine is the declaration; ProcStartLine is the blank
space above procedure.
End If
Next lngI
End Function
 
K

K

This works great! Thank you so very much!

Kim

Allen Browne said:
This kind of thing lists the procedures in a module, and the line where they
start:

Function ListProc(strModuleName As String) As String
Dim mdl As Module
Dim lngCount As Long
Dim lngCountDecl As Long
Dim lngI As Long
Dim strProcName As String
Dim intI As Integer
Dim strMsg As String
Dim lngR As Long

'lngR = vbext_pk_Proc

' Open specified Module object.
DoCmd.OpenModule strModuleName
Set mdl = Modules(strModuleName)

lngCount = mdl.CountOfLines
lngCountDecl = mdl.CountOfDeclarationLines

' Determine name of first procedure.
strProcName = mdl.ProcOfLine(lngCountDecl + 1&, lngR)

intI = 0

Debug.Print strProcName, lngR

' Determine procedure name for each line after declarations.
For lngI = lngCountDecl + 1& To lngCount
' Compare procedure name with ProcOfLine property value.
If strProcName <> mdl.ProcOfLine(lngI, lngR) Then
intI = intI + 1&
strProcName = mdl.ProcOfLine(lngI, lngR)
Debug.Print strProcName
Debug.Print , "ProcStartLine = " &
mdl.ProcStartLine(strProcName, lngR)
Debug.Print , "ProcBodyLine " & mdl.ProcBodyLine(strProcName,
lngR)
'ProcBodyLine is the declaration; ProcStartLine is the blank
space above procedure.
End If
Next lngI
End Function
 
K

K

This worked great! Thank you so much!

Kim

Allen Browne said:
This kind of thing lists the procedures in a module, and the line where they
start:

Function ListProc(strModuleName As String) As String
Dim mdl As Module
Dim lngCount As Long
Dim lngCountDecl As Long
Dim lngI As Long
Dim strProcName As String
Dim intI As Integer
Dim strMsg As String
Dim lngR As Long

'lngR = vbext_pk_Proc

' Open specified Module object.
DoCmd.OpenModule strModuleName
Set mdl = Modules(strModuleName)

lngCount = mdl.CountOfLines
lngCountDecl = mdl.CountOfDeclarationLines

' Determine name of first procedure.
strProcName = mdl.ProcOfLine(lngCountDecl + 1&, lngR)

intI = 0

Debug.Print strProcName, lngR

' Determine procedure name for each line after declarations.
For lngI = lngCountDecl + 1& To lngCount
' Compare procedure name with ProcOfLine property value.
If strProcName <> mdl.ProcOfLine(lngI, lngR) Then
intI = intI + 1&
strProcName = mdl.ProcOfLine(lngI, lngR)
Debug.Print strProcName
Debug.Print , "ProcStartLine = " &
mdl.ProcStartLine(strProcName, lngR)
Debug.Print , "ProcBodyLine " & mdl.ProcBodyLine(strProcName,
lngR)
'ProcBodyLine is the declaration; ProcStartLine is the blank
space above procedure.
End If
Next lngI
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top