Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Running Macros from Macros.
Written by Allen Wyatt (last updated September 4, 2024)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365
There may be times that you need to run a macro from within a macro using VBA. For instance, suppose you have a macro that creates a new document based on a template, and then runs a macro in that template. This is a relatively straightforward task and one way to handle it is to use the .Run method of the Application object. The command line to use this approach would be as follows:
Application.Run MacroName:="MyMacro"
Provided that there is no ambiguity on the macro name (there are no other macros in any open document or template with the same name), this approach will work just fine. A more elegant solution would be to specify the unambiguous name of the macro, as described in the next tip.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (11411) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Running Macros from Macros.
The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!
If you are applying formatting from within a macro, you may want to change the alignment of various paragraphs. Here's ...
Discover MoreDo you need to highlight certain words in a document, and aren't quite sure how to go about it? Using the techniques ...
Discover MoreOne of the math functions you can use in your macros is the Int function. It provides a way for you to derive an integer ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2019-05-13 13:01:51
Hugh
Within a macro, can't you just use the name of the macro itself as a command. For instance, instead of typing
Application.Run MacroName:="MyMacro"
couldn't you just type
MyMacro
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments