WD97: Retrieving Settings from Word Dialog Boxes Using OLE

Last reviewed: February 11, 1998
Article ID: Q159547
The information in this article applies to:
  • Microsoft Word 97 for Windows

SUMMARY

This article describes how to retrieve settings from Word dialog boxes using either Microsoft Visual Basic for Applications references or the GetObject function for OLE Automation.

MORE INFORMATION

Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

The preferred method for accessing Microsoft Word for Windows Object properties is to add the Microsoft Word 8.0 Object Library as an available reference. If you use an application that supports Visual Basic for Applications references, such as Microsoft Excel 97, to make calls to Word, your code can call Word directly without using the GetObject function.

To add Microsoft Word 8.0 Object Library in Microsoft Excel 97, follow these steps:

  1. Start Microsoft Excel.

  2. On the Tools menu, click References.

  3. Under Available References, select Microsoft Word 8.0 Object Library.

  4. Click OK.

The following example obtains the current setting for the Highlight option on the View tab in Word. (To locate this option, click Options on the Tools menu.)

   Sub GetHighlightSetting()
      Set myDialog = Word.Application.Dialogs(wdDialogToolsOptionsView)
      x$ = myDialog.Highlight
      MsgBox x$
   End Sub

In the preceding example, the wdDialogToolsOptionsView constant is referred to by name:

   Word.Application.Dialogs(wdDialogToolsOptionsView)

In the following example, reference is made to the wdDialogToolsOptionsView constant by value:

   wobj.Dialogs(204)

For readability purposes, you can create a user-defined constant, set it to equal the dialog value, and use it like a built-in constant. This also lets you change the value in one place near the top of the macro, and have the change effective throughout the macro.

For example:

   'Define a constant and set it equal to the dialog value.
   Const wdMyDialogToolsOptionsView = 204
   'Use the constant in place of the actual number.
   Set myDialog = wobj.Dialogs(wdMyDialogToolsOptionsView)

NOTE: When you use the Microsoft Word 8.0 Object Library as a reference, you can specify the Word constants by name. However, when this library is not available, you can only refer to the constant by its value. To obtain the value of a Word constant, use the Object Browser.

The Object Browser enables you to browse through all available objects in your project and see their properties, methods, and events. In addition, you can see the procedures and constants that are available from object libraries in your project. You can easily display Help as you browse. You can use the Object Browser to find and use objects you create, as well as objects from other applications.

To use the Object Browser, follow these steps:

  1. Open a module.

  2. On the View menu, click Object Browser.

  3. In the Search text box, type the constant name.

  4. Click the Search button.

    Under Details you will see the constant description including the numeric and hexadecimal value.

For more information about the Object Browser, while in the Visual Basic for Applications Editor click the Office Assistant, type "Object Browser" (without the quotation marks), click Search, and then click to view "Object Browser."

For more information about Built-in dialog box arguments, while in the Visual Basic for Applications Editor click the Office Assistant, type "Built-in dialog box arguments lists" (without the quotation marks), click Search, and then click to view "Built-in dialog box arguments lists."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft Visual Basic Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q120802
   TITLE     : Office: How to Add/Remove a Single Office Program or
               Component

Below are two examples of how to obtain Word dialog box settings from another application without adding the Microsoft Word 8.0 Object Library as a reference.

The following example obtains the current setting for the Highlight option on the View tab in Word. (To locate this option, click Options on the Tools menu.)

   Sub GetHighlightSetting()
      Const wdMyDialogToolsOptionsView = 204
      Dim Value As String
      Dim wobj As Object
      Dim myDialog As Object
      Set wobj = GetObject(, "Word.Application")
      Set myDialog = wobj.Dialogs(wdMyDialogToolsOptionsView)
      Value = myDialog.Highlight
      MsgBox Value
      wobj.Quit
      Set wobj = Nothing
      Set myDialog = Nothing
   End Sub

The following example obtains the right indent of the current active document.

   Sub GetRightIndent()
      Const wdMyDialogFormatParagraph = 175
      Dim wobj As Object
      Dim myDialog As Object
      Set wobj = GetObject(, "Word.Application")
      Set myDialog = wobj.Dialogs(wdMyDialogFormatParagraph)
      MsgBox "Right indent = " & myDialog.RightIndent
      wobj.Quit
      Set wobj = Nothing
      Set myDialog = Nothing
   End Sub

To Determine the Value of a Built-in Dialog Constant

To determine the value of a built-in dialog constant using the Object Browser, follow these steps:

  1. Press ALT+F11 to start the Visual Basic for Applications Editor.

  2. On the View menu, click Object Browser.

  3. In the Project/Library drop-down list, click Word.

  4. In the Search Text box type "wdDialog" (without the quotation marks).

  5. Click the Search (binoculars) button. This returns a list of all built- in dialog constants.

  6. Under Search Results, click to select the constant you want. The value of the constant is displayed near the bottom of the Object Browser window.

REFERENCES

For more information about OLE Automation, while in the Visual Basic for Applications Editor click the Office Assistant, type "GetObject" (without the quotation marks), click Search, and then click to view "GetObject."

For information about how to do this in earlier versions of Word, please see the following articles in the Microsoft Knowledge Base:

   ARTICLE-ID: Q105684
   TITLE     : OLE Automation: Retrieving Word's Dialog Box Settings

   ARTICLE-ID: Q114347
   TITLE     : How OLE Automation Objects Behave with GetObject &
               CreateObject


Additional query words: 8.0 8.00 vb vbe vba
Keywords : kbwordvba kbfaq
Version : WINDOWS:97
Platform : WINDOWS
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 11, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.