I am writing a reporting tool to document Excel files for various “compliance criteria”, including wkb.VBProject.Protection to report if the VBA is locked.
But how can I find if the workbook HAS any project ?
If I calculate
wkb.VBProject.VBComponents.Count - wkb.Worksheets.Count - 1 '(for the workbook)
that will give me the number of modules + class modules + forms, but I could still have some code behind a sheet.
Is there a way in Excel – like Access frm.HasModule – to find out if there’s any VBA code in the workbook ?
I’ve used the following to count the total number of lines in a project before. It will pick up code in
ThisWorkbook, code modules, class modules and forms.Note however that if your workbooks have
Option Explicitforced then this will count as two lines per object (Option Explicitand a line feed). If you know this to be the case, and are checking the LOC from another project, then you could simply count the number of objects, double it and test thatVBALineCountdoes not exceed this number.