Microsoft Office 2000/Visual Basic Programmer's Guide   

Working with the Settings in the Options Dialog Box

The Options dialog box contains many settings that let you customize the way Word looks and behaves. You can view this dialog box by clicking Options on the Tools menu. To programmatically access the settings in this dialog box, you use the Options object or the View object of a Window object. You can also access these settings through the Dialog object that represents the tab in the Options dialog box that contains the setting you want to manipulate.

Note   For information about using built-in Word dialog boxes to perform actions other than the built-in behavior, see "Working with Word Dialog Boxes" later in this chapter.

Using the Options Object

The Options object contains many properties that represent items in the Options dialog box. For example, the Options object's ReplaceSelection property setting is equivalent to the Typing replaces selection setting on the Edit tab of the Options dialog box. The easiest way to identify which properties of the Options object represent settings on a tab in the Options dialog box is to record a macro that changes a setting and then examine the property settings Word records. For example, the Print tab of the Options dialog box contains fourteen settings. Two settings (Print PostScript over text and Print data only for forms) apply only to the active document and are therefore properties of the Document object. The remaining settings represent properties of the Options object. A macro that records a change to a setting on the Print tab would create, in part, the following list of Options object properties:

With Options
   .UpdateFieldsAtPrint = False
   .UpdateLinksAtPrint = False
   .DefaultTray = "Use printer settings"
   .PrintBackground = True
   .PrintProperties = False
   .PrintFieldCodes = False
   .PrintComments = True
   .PrintHiddenText = True
   .PrintDrawingObjects = True
   .PrintDraft = False
   .PrintReverse = False
   .MapPaperSize = True
End With

If you change the settings of Options object properties, make sure you return each setting to its original value when you are finished. Many of these properties are global application-level settings, and you may be making changes that the user would not want persisted. The following example illustrates how to return Options object properties to their original settings when a procedure that changes those properties ends:

Sub PrintAllDocInfo()
   ' This procedure illustrates how to use the Options object
   ' to change certain settings, print a document, and then
   ' return the settings to their original state.
   Dim blnProps         As Boolean
   Dim blnFields        As Boolean
   Dim blnComments      As Boolean
   Dim blnHidden        As Boolean
   
   With Options
      ' Save the existing property settings.
      blnProps = .PrintProperties
      blnFields = .PrintFieldCodes
      blnComments = .PrintComments
      blnHidden = .PrintHiddenText
      ' Set properties to True and print document.
      .PrintProperties = True
      .PrintFieldCodes = True
      .PrintComments = True
      .PrintHiddenText = True
      Application.PrintOut
      ' Return properties to original settings.
      .PrintProperties = blnProps
      .PrintFieldCodes = blnFields
      .PrintComments = blnComments
      .PrintHiddenText = blnHidden
   End With
End Sub

To try the PrintAllDocInfo procedure, open the WordOptions.doc sample file in the ODETools\V9\Samples\OPG\Samples\CH05 subfolder on the Office 2000 Developer CD-ROM and print a copy of the document. Then run the PrintAllDocInfo procedure in the modOptionsDialog module and compare the printed output between the two versions of the document.

Using the View Object and the Dialog Object

The View object lets you determine or specify all the attributes of a Window object. For example, you can run the following code sample from the Immediate window in the Visual Basic Editor to determine whether hidden text is displayed in the current document:

? ActiveWindow.View.ShowHiddenText

Note that although many of the View object properties map directly to settings in the Options dialog box, they do not necessarily map to settings on the View tab of that dialog box.

You use the Dialogs collection to access a Dialog object that represents a tab in the Options dialog box. For example, if you execute the following code from the Immediate window, it prints the current setting for the Typing replaces selection check box on the Edit tab of the Options dialog box:

? CBool(Dialogs(wdDialogToolsOptionsEdit).ReplaceSelection)