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

Making Word Remember My Settings

Ever had the experience of setting some configuration option in Word, only to have the option revert to a different setting ...

Discover More

Finding Where Templates Are Stored

The first step in modifying templates is to find out where they are stored on your system. Here's the easiest way to figure ...

Discover More

Using Subtotals and Totals

You can insert subtotals and totals in your worksheets by using either a formula or specialized tools. This tip explains how ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More WordTips (ribbon)

Determining if Num Lock is On

Need to know if the Num Lock key is on or off? You can use a short bit of macro code to figure out the state of the key.

Discover More

Setting the Right Indent of a Paragraph in a Macro

Need to format your document using a macro? You can easily set the right margin for an individual paragraph by using the ...

Discover More

Understanding Subroutines

The heart of creating powerful programs in VBA is to understand how to create subroutines. These structures allow you to ...

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 8Mpixels. 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 0 + 7?

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.