ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Count lines code in workbook (https://www.excelbanter.com/excel-programming/374001-count-lines-code-workbook.html)

Arnold Klapheck

Count lines code in workbook
 
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

Alok

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


Arnold Klapheck

Count lines code in workbook
 
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

Alok

Count lines code in workbook
 
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

"Arnold Klapheck" wrote:

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


Arnold Klapheck

Count lines code in workbook
 
Thanks, that did it works great now.

laura_in_abq

Count lines code in workbook
 
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

"Alok" wrote:

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

"Arnold Klapheck" wrote:

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


Dave Peterson

Count lines code in workbook
 
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.

laura_in_abq wrote:

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

"Alok" wrote:

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

"Arnold Klapheck" wrote:

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


--

Dave Peterson


All times are GMT +1. The time now is 05:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com