Solved Count lines of code in a VBA project?

theKruser

Registered User.
Local time
Today, 01:39
Joined
Aug 6, 2008
Messages
122
Anyone know how to see the total number of lines of code in an Access 2007 database?

I have tried CountLines() and ContOfLines() (with and without a leading '?') in the immediate window, but it errors, "Compile error: Expected: ="

Any ideas?
 
Code:
Function CountVbaLines()

On Error GoTo ErrorHandler

'******************************************************************************
'_____________________________________________________________________________*
'                                                                             |
'THIS FUNCTION REQUIRES A REFERENCE TO THE "MICROSOFT VISUAL BASIC            |
'EXTENSIBILITY LIBRARY 5.3 (OR EARLIER VERSION)"                              |
'_____________________________________________________________________________|
'                                                                             *
'******************************************************************************

Dim TotalLines As Double
Dim vbEditor As VBIDE.VBE
Dim VBProj As VBIDE.VBProject
Dim VBobj As VBIDE.VBComponent

Set vbEditor = Application.VBE
Set VBProj = vbEditor.ActiveVBProject

   For Each VBobj In VBProj.VBComponents

      TotalLines = TotalLines + VBobj.CodeModule.CountOfLines
   
   Next VBobj
   
      CountVbaLines = TotalLines

ErrorHandler:
   Set vbEditor = Nothing
   Set VBProj = Nothing

End Function '//LL
 
I know the_net_2.0 has given you some code to get the code lines, but you do realise that you can see the number of lines in the Standard Toolbar?
 
@the_net_2.0
I just typed that all in and got an error. Then I saw the line that said VBA 5.3 or earlier needed. I am running 6.5. Any other ideas?

@vbaInet
The standard tool bar gives you the line you are on, not the total number of lines in the project including modules. Unless you know something I don't. I am all ears...er...um...I guess eyes.
 
That was just an fyi. I thought you were after the number of lines in the module you're on. the_net_2.0's code should get you what you need.

What error are you getting? And what version of Access are you running?
 
I am running 2007. I was getting a user defined variable type error. I just set the vars as variant and it works fine now.

Thanks for the help!!
 

Users who are viewing this thread

Back
Top Bottom