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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:24:44+00:00 2026-05-13T19:24:44+00:00

I’m trying to call an Excel macro that’s in another workbook. It’s a sheet-specific

  • 0

I’m trying to call an Excel macro that’s in another workbook. It’s a sheet-specific macro, but the syntax given by Microsoft documentation and researching on the web, only gives a way to access a macro by workbook only. That syntax is:

Application.Run ("testworkbook.xls!macroname")

What I need to do is have a sheet reference in there also, something like:

Application.Run ("testworkbook.xls!Sheet1.macroname")

I’ve tried this and MANY other variations, including having single or double quotes in there, but I always get the message that the macro cannot be found.

Edit: With all the clues and much testing I found the answer. You can access Sheet-specific subs, but you have to use the canonical name like ‘Sheet1’, you can’t use the actual sheetname. Apparently other workbooks don’t access that information.

So the format above works as long as you don’t try to use the sheetname (and you may have to single quote the workbook name (by concatenating CHR(39) to either end).

  • 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-13T19:24:44+00:00Added an answer on May 13, 2026 at 7:24 pm

    I know you’ve figured this out, probably after much hair-tearing and coffee, but I wanted to:

    • Give you more details on why this is
    • Provide you with a way you could use
      your sheet’s name to get what you
      want.

    First of all, the worksheet name you are wanting is not the same thing as the code module name. So in your VBE, you see that the name of the code module is “Sheet1”, but if may have a different property of Name which is different, for example, “MySheet1” (or it also may be the same).

    In order to get it by name, you’ll have to do some loops, change security settings, etc. If that’s what you’re after (this works well in smaller environments because of the security setting issue), here you go as an example:

    1. Change your security settings to
      trust programmatic access to VBA
      Projects. In Excel 2007, go to Orb | Excel Options | Trust Center | Trust Center Settings | Macro
      Settings and then enable “Trust
      access to the VBA project model”
    2. Create a workbook with one
      worksheet. Rename it “MySheet1“.
      Open the VBE (Alt+F11) and in
      “Sheet1 (MySheet1)” create a sub
      routine, call it TimesTen and in
      the code just put Debug.Print 10 *
      10
      . Like this:

      Sub TimesTen()
          Debug.Print 10 * 10
      End Sub
      
    3. Save the file as an macro-enabled
      document and call it
      “MacroXSLX.xlsm“. Leave it open.

    4. Open a new Excel document, navigate
      to it’s VBE and in a new macro
      anywhere, create a sub called
      Test. In the body of that code,
      put this:
      .

      Sub test()
      Dim SheetName As String
      SheetName = "MySheet1"
      Dim wb As Workbook
      Set wb = Workbooks("MacroXSLX.xlsm")
      For Each VBComp In wb.VBProject.VBComponents
          If VBComp.Properties.Item("Name").Value = SheetName Then
              Application.Run (wb.Name & "!" & VBComp.Name & ".TimesTen")
          End If
      Next
      End Sub
      
    5. Press F5 to run test and you
      should see 100 in the Immediate
      window.

    You can see in #4 that I’m looping through all the components (Modules, Classes, etc.) looking for the one that has a Name property that has a value of MySheet1. Once I have that, I can then get the name of that component, which in this case is Sheet1 and use that to construct my string that will run the sheet’s macro in MacroXSLX.xlsm. The code can be cleaned up further to exit the For statement when you’ve found what you want, etc.

    As mentioned above, the only real draw-back to this is the security settings piece and ensuring you have programmatic access to the VBAProject – fine on one to ten computers, but could be a hassle if you have to ensure more than that are always set correctly.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and

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.