Hello all,
I'm using Excel 2003, and my reporting application is in wrap-up for distribution. In order to estimate my remaining efforts, I created a worksheet "ModuleList" and the macro ListModules does it's work. However, via "VBIDE.vbext_ProcKind" I get only "Sub or Function". I would like to get "Sub" if it is a sub, "Function" if it is a function.
In fact I need the very first line, like
(Public/Private) Function DoSomethingAndReturnValue(InputA as String) As Long OR
(Public/Private) Sub DoSomething(InputA As String)
It' not exactly a show-stopper but it would be nifty to have it.
Thanks for having a look. Code is below.
Isabella
[vba]
Sub ListModules()
Dim boolIsSub As Boolean
Dim boolHasComment As Boolean
Dim EL As Long
Dim LineNum As Long
Dim NumLines As Long
Dim strCompType As String
Dim ProcName As String
Dim FindSub As String
Dim FindComment As String
Dim VBProj As Object
Dim VBEPart As Object
Dim WS As Worksheet
Dim Rng As Range
Dim aCodeMod As VBIDE.CodeModule
Dim ProcKind As VBIDE.vbext_ProcKind
Set collVBParts = New Collection
Set VBEPart = Application.VBE.ActiveVBProject.VBComponents
Set VBProj = ActiveWorkbook.VBProject
Set WS = ActiveWorkbook.Worksheets("ModuleList")
Set Rng = WS.Range("A3")
'WS.Range("A3").CurrentRegion.Clear
FindSub = "Sub"
FindComment = "'* Module: *"
'Dim myMod As Object
'Set myMod = VBProj.VBComponents("DataSources")
For Each VBEPart In VBProj.VBComponents
strCompType = ComponentTypeToString(VBEPart.Type)
If strCompType = "UserForm" Or strCompType = "Code Module" Then
Set aCodeMod = VBEPart.CodeModule
Rng(1, 4).Value = VBEPart.Name
Rng(1, 5).Value = ComponentTypeToString(VBEPart.Type)
With aCodeMod
LineNum = .CountOfDeclarationLines + 1
EL = .CountOfLines
Do Until LineNum >= .CountOfLines
ProcName = .ProcOfLine(LineNum, ProcKind)
Rng.Value = ProcName
GoSub GetDetails
LineNum = .ProcStartLine(ProcName, ProcKind) + _
.ProcCountLines(ProcName, ProcKind) + 1
Set Rng = Rng(2, 1)
Loop
End With
Set Rng = Rng(2, 1)
Else
GoTo ContinueSearch
End If
ContinueSearch:
Next VBEPart
Exit Sub
GetDetails:
boolIsSub = aCodeMod.Find(target:=FindSub, StartLine:=1, StartColumn:=1, _
EndLine:=EL, EndColumn:=20, _
wholeword:=True, MatchCase:=False, Patternsearch:=False)
If boolIsSub = True Then
'Debug.Print ProcName + " is Sub"
Rng(1, 2).Value = "Sub"
Else
'Debug.Print ProcName + " is Function"
Rng(1, 2).Value = "Function"
End If
boolHasComment = aCodeMod.Find(target:=FindComment, StartLine:=1, StartColumn:=1, _
EndLine:=EL, EndColumn:=20, _
wholeword:=True, MatchCase:=False, Patternsearch:=False)
If boolHasComment = True Then
'Debug.Print ProcName + " has Comment"
Rng(1, 3).Value = "has Comment"
Else
'Debug.Print ProcName + " Comment is missing"
Rng(1, 3).Value = "Comment is missing"
End If
boolIsSub = False
boolHasComment = False
Return
End Sub
Function ComponentTypeToString(ComponentType As VBIDE.vbext_ComponentType) As String
Select Case ComponentType
Case vbext_ct_ActiveXDesigner
ComponentTypeToString = "ActiveX Designer"
Case vbext_ct_ClassModule
ComponentTypeToString = "Class Module"
Case vbext_ct_Document
ComponentTypeToString = "Document Module"
Case vbext_ct_MSForm
ComponentTypeToString = "UserForm"
Case vbext_ct_StdModule
ComponentTypeToString = "Code Module"
Case Else
ComponentTypeToString = "Unknown Type: " & CStr(ComponentType)
End Select
End Function
Function ProcKindString(ProcKind As VBIDE.vbext_ProcKind) As String
Select Case ProcKind
Case vbext_pk_Get
ProcKindString = "Property Get"
Case vbext_pk_Let
ProcKindString = "Property Let"
Case vbext_pk_Set
ProcKindString = "Property Set"
Case vbext_pk_Proc
ProcKindString = "Sub Or Function"
Case Else
ProcKindString = "Unknown Type: " & CStr(ProcKind)
End Select
End Function[/vba]