Hi,
I have a macro (from Pearson Software Consulting) that can count the number of rows of a Module. But as I run it, got something like 'compile error: type mismatch'. Trying to get around but failed. Here is the code:
Thanks in advance.
Public Function TotalCodeLinesInVBComponent(VBComp As VBIDE.VBComponent) As Long
Dim N As Long
Dim S As String
Dim LineCount As Long
If VBComp.Collection.Parent.Protection = vbext_pp_locked Then
TotalCodeLinesInVBComponent = -1
Exit Function
End If
With VBComp.CodeModule
For N = 1 To .CountOfLines
S = .Lines(N, 1)
If Trim(S) = vbNullString Then
' blank line, skip it
ElseIf Left(Trim(S), 1) = "'" Then
' comment line, skip it
Else
LineCount = LineCount + 1
End If
Next N
End With
TotalCodeLinesInVBComponent = LineCount
End Function
Sub tntt()
x = TotalCodeLinesInVBComponent(Module1)
MsgBox x
End Sub
I have a macro (from Pearson Software Consulting) that can count the number of rows of a Module. But as I run it, got something like 'compile error: type mismatch'. Trying to get around but failed. Here is the code:
Thanks in advance.
Public Function TotalCodeLinesInVBComponent(VBComp As VBIDE.VBComponent) As Long
Dim N As Long
Dim S As String
Dim LineCount As Long
If VBComp.Collection.Parent.Protection = vbext_pp_locked Then
TotalCodeLinesInVBComponent = -1
Exit Function
End If
With VBComp.CodeModule
For N = 1 To .CountOfLines
S = .Lines(N, 1)
If Trim(S) = vbNullString Then
' blank line, skip it
ElseIf Left(Trim(S), 1) = "'" Then
' comment line, skip it
Else
LineCount = LineCount + 1
End If
Next N
End With
TotalCodeLinesInVBComponent = LineCount
End Function
Sub tntt()
x = TotalCodeLinesInVBComponent(Module1)
MsgBox x
End Sub