Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 321993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:53:49+00:00 2026-05-12T08:53:49+00:00

I am writing a reporting tool to document Excel files for various compliance criteria,

  • 0

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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T08:53:49+00:00Added an answer on May 12, 2026 at 8:53 am

    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.

    Private Sub countCodeLines()
        Dim obj As Object
        Dim VBALineCount As Long
        For Each obj In ThisWorkbook.VBProject.VBComponents
            VBALineCount = VBALineCount + obj.CodeModule.CountOfLines
        Next obj
        Debug.Print VBALineCount
    End Sub
    

    Note however that if your workbooks have Option Explicit forced then this will count as two lines per object (Option Explicit and 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 that VBALineCount does not exceed this number.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im writing a report with Reporting services that is almost always only going to
I've been tasked with converting some text log files from a test reporting tool
I'm new to reporting svcs and I'm writing a report based on a report
Writing a rather simple command line tool in ruby I need to report meaningful
Writing a Reporting Service (2005) report My DataSet returns something like this: DESCRIPTION COUNT
I am writing a custom error handling / reporting function for PHP file upload
Writing the code for the user authentication portion of a web site (including account
I'm writing reports on SQL Server Reporting Server that have a number of hours
I'm writing desktop app in c# and I need some free reporting system. Any
I'm writing an XSL transform in Visual Studio. It is reporting that the semicolon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.