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

Additional Members of the Document Object

Some additional members of the Document object include:

The Activate method

Activates the document, thus making it the active document. For instance, to activate a document named MyLetter, execute the code:

Documents("MyLetter").Activate
The AttachedTemplate property

Returns a Template object that represents the template that is currently attached to the document. By setting this property, you can attach a new template to the document. For instance, the following code attaches the template FaxDocs to the current document:

ActiveDocument.AttachedTemplate = "FaxDocs.dot"
The ComputeStatistics method

This method returns information about the document. It syntax is:

DocumentObject.ComputeStatistics(Statistic, IncludeFootnotesAndEndnotes)

where Statistic is one of the following constants:

Enum WdStatistic
   wdStatisticWords = 0
   wdStatisticLines = 1
   wdStatisticPages = 2
   wdStatisticCharacters = 3
   wdStatisticParagraphs = 4
   wdStatisticCharactersWithSpaces = 5
End Enum

The parameter IncludeFootnotesAndEndnotes is set to True to include footnotes and endnotes when computing the requested information. The default value of this parameter is False.

Incidentally, Word can supply more statistics about a document through the DocumentStatistics dialog box. (I explain how to access this information at the end of Chapter 19, Built-in Dialog Objects.)

The Content property

This useful property returns a Range object that represents the main document story. (I show it ...

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