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 1087407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:56:07+00:00 2026-05-16T22:56:07+00:00

Question How do I access a public constant defined in another Excel workbook? Setup

  • 0

Question

How do I access a public constant defined in another Excel workbook?

Setup

Workbook.xls

My VBA code runs in the current Excel workbook called “MyWorkbook.xls”.
It has some VBA code in it which reads a file name –“OtherWorkbook.xls in this case– from cell “A1”. Then, the code should read a constant defined in that other workbook and write it to cell “A2”. Here is what my code looks like:

Sub GetValueFromOtherWorkbook()
    otherWorkbook = Range("A1").Value  ' Value = "OtherWorkbook.xls"

    Dim returnedValue As String

    ' Idea 1: Doesn't work
    Set returnedValue = OtherWorkbook.xls!Module1.MY_CONSTANT

    ' Idea 2: Doesn't work either
    Set returnedValue = Application.Run(otherWorkbook & "!Module1.MY_CONSTANT")

    Range("A2").Value = returnedValue ' MY_CONSTANT = "testValue"
End Sub

OtherWorkbook.xls

The second Excel workbook is called “OtherWorkbook.xls” as mentioned above.
It has a VBA module called Module1.
Module1 defines a public constant. The code looks like this:

Public Const MY_CONSTANT As String = "testValue"

Problem

The code from MyWorkbook.xls does not run, it returns the following error

Run-time error ‘424’

Object required

I don’t quite know what to do with it even after reading the help documentation. In another context, I managed to call a routine in another workbook with this code:

otherWorkbookName = "OtherWorkbook.xls"
Application.Run (otherWorkbookName & "!Module1.SomeRoutine")

So, calling a routine works, but accessing a public constant does not.

Any ideas what I could try next?

  • 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-16T22:56:08+00:00Added an answer on May 16, 2026 at 10:56 pm

    A code module is not an object that can be accessed like a worksheet.

    You can access and manipulate it, but in order to do that you need to reference the Microsoft Visual Basic for Applications Extensibility library and allow access to the VBA project (Tools – Options – Security – Macro security – Trusted publishers – Trust access to VBA project), after which you can use the Workbook.VBProject property of the second workbook.

    You don’t need to do this. Instead you can create a reference to the other workbook: in VBA IDE, go Tools – References, click Browse and locate your workbook with the constant.

    If that’s no good, you can create a method in that workbook that only returns the value of the constant, and call it as you have demonstrated.

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

Sidebar

Related Questions

The question regarding the Umbraco CMS: I have to setup public access for particular
Basic question - is it possible to access the current Page from a static
I have a question about Access.If for example I have a table with the
I have a short access/mySQL question. I have a mapping table on the format
Basically this is a question how to access local scope handler. I trying to
my question is about two possible ways to access data: (My question is about
I have a smple Question: How can I access to a class and its
I have a question about how to access the member with the same name
This question involves 3 tables and 1 form in my Access database. The tables
QUESTION : In .NET 3.5 WinForms apps, how do I access/call methods in UI

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.