View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Alok Alok is offline
external usenet poster
 
Posts: 318
Default Count lines code in workbook

Use the following code

Public Function CountLines() As Long
Dim ovbp As VBProject
Dim ovbc As VBComponent
Dim lTotLines As Long
Set ovbp = ThisWorkbook.VBProject
For Each ovbc In ovbp.VBComponents
Debug.Print ovbc.Name, ovbc.CodeModule.CountOfLines
lTotLines = lTotLines + ovbc.CodeModule.CountOfLines
Next ovbc
CountLines = lTotLines
End Function

Make sure that the project References Visual Basic Extensibility library.

"Arnold Klapheck" wrote:

I was wanting to count the lines of code in my workbook which has many
modules, I downloaded the count Loc program but can't seem to get it to run,
does anyone have some code to count lines of code in an entire workbook
including sheets and modules, possibly skipping comments? thanx