Counting Code Lines in a Project

chappy

Registered User.
Local time
Today, 20:00
Joined
Nov 5, 2003
Messages
30
I'm interested in counting the executable lines of code in a vba project. Does anyone out there know how to get the line count of a vba project's code? The only way I'm aware of retrieving a line count is to scroll to the end of each module and read of the line count from the visual basic editor. This method is tedious. I've investigated the VBE object but I haven't found any property or method to return a line count for project modules and forms. Any thoughts?

-Chappy
 
Code:
Public Sub CountLinesInModules()

    On Error GoTo Err_CountLinesInModules

    Dim lngCounter As Long
    Dim lngTotal As Long
    Dim modModule As Module

    For lngCounter = 0 To Modules.Count - 1
        Set modModule = Modules.Item(lngCounter)
        With modModule
            Debug.Print .Name & ": " & .CountOfLines
            lngTotal = lngTotal + .CountOfLines
        End With
    Next lngCounter
    Debug.Print "Overall: " & lngTotal
    
Exit_CountLinesInModules:
    Set modModule = Nothing
    Exit Sub
    
Err_CountLinesInModules:
    MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
    Resume Exit_CountLinesInModules
    
End Sub
 
Just what I needed. Thanks!

-Chappy
 

Users who are viewing this thread

Back
Top Bottom