List all procedures within a module

  • Thread starter Thread starter K
  • Start date Start date
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
 
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
 
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
 
Back
Top