CountOfLines for a sheet module

drom

Well-known Member
Joined
Mar 20, 2005
Messages
527
Office Version
  1. 2021
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Close:
Rich (BB code):
Debug.Print ThisWorkbook.VBProject.VBComponents("ThisWorkbook").codemodule.CountOfLines
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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
Back
Top