CountOfLines for a sheet module

drom

Active Member
Joined
Mar 20, 2005
Messages
491
Office Version
  1. 2019
  2. 2016
  3. 2013
  4. 2011
  5. 2010
  6. 2007
Thanks Ina Advance!

if I want to count the number of lines my "ThisWorkbook" sheets module or any other Sheets module has...

I can use the following macro:

Rich (BB code):
Sub Count_CLS_Lines()
  On Error Resume Next
Dim WkbName As String: WkbName = "Z:\MrExcel\Eg_20080309.xlsm"
Dim VBComp As VBIDE.VBComponent
Dim VBComps As VBIDE.VBComponents:  Set VBComps = Workbooks(WkbName).VBProject.VBComponents
  For Each VBComp In VBComps 'For X= ...
    Select Case VBComp.Type
      Case vbext_ct_Document:         'VBComps.Remove VBComp   '100:"Document"
        With VBComp.CodeModule
          If .CountOfLines > 0 Then
            
            Debug.Print .CountOfLines ''???????????????????????????
            
          End If
        End With
    End Select
  Next VBComp
  beep
End Sub


But is there any other way of doing this rather than the prior one?

Kind of:

Rich (BB code):
Debug.Print ThisWorkbook.VBProject.VBComponents("Sheet1").CountOfLines
Debug.Print ThisWorkbook.VBProject.VBComponents("thisWorkbook").CountOfLines

Thanks!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,426
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
Close:
Rich (BB code):
Debug.Print ThisWorkbook.VBProject.VBComponents("ThisWorkbook").codemodule.CountOfLines
 
Upvote 0

Forum statistics

Threads
1,191,532
Messages
5,987,123
Members
440,080
Latest member
drhorn4908

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top