O'Reilly logo

Writing Word Macros, Second Edition by Steven Roman PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding, Opening, and Saving Documents

Document objects have the following expected methods for document housekeeping:

The Add method

The Add method of the Documents collection creates a new Word document and adds it to the Documents collection. The new document becomes the active document. The syntax is:

DocumentsObject.Add(Template, NewTemplate)

where Template is the name of the template to be used for the new document. If this argument is omitted, the Normal template is used. The NewTemplate parameter can be set to True to open the document as a template. The default value is False.

The Open method

The Open method of the Documents collection opens an existing document and adds it to the Documents collection. The syntax is a bit involved:

DocumentsObject.Open(FileName, ConfirmConversions, _
   ReadOnly, AddToRecentFiles, PasswordDocument, _
   PasswordTemplate, Revert, WritePasswordDocument, _
   WritePasswordTemplate, Format)

All of these parameters are variants, and all except FileName are optional.

The parameters that do not relate to password protection are:

FileName

The name of the document (can include a complete path).

ConfirmConversions

Set to True to display the Convert File dialog box if the file is not in Microsoft Word format.

ReadOnly

Set to True to open the document as read-only.

AddToRecentFiles

Set to True to add the filename to the list of recently used files at the bottom of the File menu.

Revert

Controls what happens if FileName is already open. Set the parameter to True to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required