Document Object
TOC
Collapse the table of content
Expand the table of content

Document Object (Word)

Office 2013 and later
GitHub-Mark-64px

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Represents a document. The Document object is a member of the Documents collection. The Documents collection contains all the Document objects that are currently open in Word.

Use Documents(Index), where Index is the document name or index number to return a single Document object. The following example closes the document named "Report.doc" without saving changes.

Documents("Report.doc").Close SaveChanges:=wdDoNotSaveChanges

The index number represents the position of the document in the Documents collection. The following example activates the first document in the Documents collection.

Documents(1).Activate

Using ActiveDocument

You can use the ActiveDocument property to refer to the document with the focus. The following example uses the Activate method to activate the document named "Document 1." The example also sets the page orientation to landscape mode and then prints the document.

Documents("Document1").Activate 
ActiveDocument.PageSetup.Orientation = wdOrientLandscape 
ActiveDocument.PrintOut
Show:
© 2016 Microsoft