Count lines code in workbook

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
I cant find it under "Visual Basic Extensibility" or "Extensiblility"
library. Is it under a different name or do I have to import it?

thanks
 
It is called
Microsoft Visual Basic For Applications Extensibility n.n
The numbers at the end are not important. You go to Tools/References and
check on the above and hit OK.
Alok
 
Please help, what to do???
I tried that which was suggested in this thread and got this error:
Run-time error '1004': Programmatic access to Visual Basic Project is not
trusted
on this line in Alok's code:
Set ovbp = ThisWorkbook.VBProject

Thanks
Laura
 
xl2002+ offers the user more security.

There's an option under: Tools|Macro|Security|Trusted Publishers

Check "trust access to Visual Basic Project"

This setting is a user-by-user setting. Your code can't change it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top