WD97: Retrieving Settings from Word Dialog Boxes Using OLELast reviewed: February 11, 1998Article ID: Q159547 |
The information in this article applies to:
SUMMARYThis 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 INFORMATIONMicrosoft 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:
Sub GetHighlightSetting() Set myDialog = Word.Application.Dialogs(wdDialogToolsOptionsView) x$ = myDialog.Highlight MsgBox x$ End SubIn 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:
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 ComponentBelow 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 SubThe 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 ConstantTo determine the value of a built-in dialog constant using the Object Browser, follow these steps:
REFERENCESFor 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |