Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, and 2013. 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: Creating a New Document in VBA.

Creating a New Document in VBA

by Allen Wyatt
(last updated November 16, 2013)

2

One of the common things done during a macro is to create a new document. For instance, your macro could need the new document to hold processed text, or a different version of the document on which you are working.

To create a new document, simply include this line in your VBA macro:

Documents.Add

This creates a new document, based on Normal.Dot, adds it to the Documents collection, and makes the document active. This is the same as clicking the New button on the toolbar. If you want to create a new document based on a different template, simply use this command:

Documents.Add("MyTemplate.dot")

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12725) applies to Microsoft Word 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Word here: Creating a New Document in VBA.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Replacing Text in a Macro

When using a macro to process text in a document, it is not unusual to replace one portion of a text string with another ...

Discover More

Generating Double-Digit Random Numbers

Normally you use the RAND and RANDBETWEEN functions to generate random numbers. What if you want to generate random numbers ...

Discover More

Formatting a Cover Page

Formal reports look better when they are set up with an introductory cover page. Here's how you can add a cover page in a ...

Discover More

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!

More WordTips (ribbon)

Changing a Macro Description

Part of documenting macros is to provide a good, succinct description of what they do. Changing the description of an ...

Discover More

Attaching Macros to Documents

When you distribute documents to other people, you may want those documents to have associated macros that the reader can ...

Discover More

Changing ToolTips for a Macro Button

Want to change the ToolTip that appears when you hover the mouse pointer over a tool on the Quick Access Toolbar? Here's how ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is eight minus 2?

2015-06-04 14:09:58

Marcel Marien

I would find it helpful to find on the Document.Add page a hint about how to address a newly added document. Not every time the document name "Document1" will be assigned.


2014-10-14 19:07:10

Ryan G

Hi,
I have been trying to figure out how to do something and thought you might know.
I am trying to create a new document from a template within another Word Document.
If I call Word.Documents.Add template:="C:TemplatesTest.dotm", the new document opens based on that template but the calling document is locked until that new document is closed.
If I can Word.Documents.Open filename="C:Templatestest.dotm", it opens in its own window and the original document is able to be edited.
I need to be able to create a new document based on a template from within a template without adding it to the Documents collection. Is this possible in VBA? Any suggestions are appreciated.


This Site

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.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.