Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Calling a Macro from another workbook

This is a discussion on Calling a Macro from another workbook within the Excel Questions forums, part of the Question Forums category; What's the syntax to call a macro in another workbook? Thanks, Ricardo...

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Posts
    363

    Default Calling a Macro from another workbook

    What's the syntax to call a macro in another workbook?

    Thanks,
    Ricardo
    It's never too late to learn something new.

    Ricky

  2. #2
    Board Regular
    Join Date
    Mar 2003
    Location
    SoCal
    Posts
    148

    Default Re: Calling a Macro from another workbook

    willyour other workbook be open at the time??

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Posts
    363

    Default Re: Calling a Macro from another workbook

    Yes it will be open at the time.
    It's never too late to learn something new.

    Ricky

  4. #4
    Board Regular
    Join Date
    Apr 2003
    Posts
    181

    Default Re: Calling a Macro from another workbook

    Application.Run "MacroBook!MacroName"

  5. #5
    Board Regular
    Join Date
    Mar 2003
    Location
    SoCal
    Posts
    148

    Default Re: Calling a Macro from another workbook

    This is straight from the VBA guide:

    If you give the same name to two different procedures in two different projects, you must specify a project name when you call that procedure. For example, the following procedure calls the Main procedure in the MyModule module in the MyProject.vbp project.
    Code:
    Sub Main()
    	[MyProject.vbp].[MyModule].Main
    End Sub

  6. #6
    Board Regular
    Join Date
    Apr 2011
    Posts
    65

    Default Re: Calling a Macro from another workbook

    Quote Originally Posted by Jaamie View Post
    Application.Run "MacroBook!MacroName"
    I have tried this over and over again and everytime it tells me

    "Can not run the macro 'Weekly Shrinkage Tool.xlsm!NewWeek'. The macro may not be available is this workbook or all macros may be disabled."

    I have tried all sorts of versions of the line

    Application.Run "MacroBook!MacroName"

    including using a variable for the file name which I can't get to work at all

    but here are some ways I have typed it

    Application.Run "Weekly Shrinkage Tool.xlsm!NewWeek"
    Application.Run "Weekly Shrinkage Tool.xlsm!NewWeek()"
    Application.Run "Weekly Shrinkage Tool.xlsm!Public Sub NewWeek()"
    Application.Run "Weekly Shrinkage Tool!NewWeek"

    Am I missing something like a simple sintax error?

  7. #7
    Board Regular
    Join Date
    Apr 2010
    Location
    Prague, CZ
    Posts
    316

    Default Re: Calling a Macro from another workbook

    yeah, I get the same error

    help appreciated

  8. #8
    Board Regular
    Join Date
    Apr 2010
    Location
    Prague, CZ
    Posts
    316

    Default Re: Calling a Macro from another workbook

    Found the solution

    if you try to run a macro from a workbook that contains spaces you must enclose them with apostrophe, such as

    Code:
    Application.Run ("'Analytics macro S17.xlsm'!getdata")

  9. #9
    New Member
    Join Date
    Nov 2010
    Location
    New York, NY
    Posts
    25

    Default Re: Calling a Macro from another workbook

    I am trying to do the same thing and continue to get the error "Cannot run the macro 'DPUSetup'. The macro may not be available in this workbook or all macros may be disabled."

    I have checked and rechecked my macro security settings, there are no other macros, procedures, etc. with any duplicate names, and I have done this before on a different computer and it has worked perfectly. I just want one wb where all my macros live and want to run them all off that wb by selecting a macro icon on my quick access toolbar regardless of the actual wb that I am editing. Also, regarding the answer above, this macro in particular is coming from a brand new wb every day, so I don't want to build an application.run macro in that new wb just to run one macro every day. That doesnt make sense.

    Please help!

  10. #10
    New Member
    Join Date
    Jul 2013
    Posts
    1

    Default Re: Calling a Macro from another workbook

    If the name of the workbook is dynamically assigned as a variable you can use this code

    Application.Run ("'" & workbookname & "'!macroname")

Page 1 of 3 123 LastLast

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com