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 ...

Get Writing Word Macros, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.