Microsoft KB Archive/108686

{|
 * width="100%"|

Displaying a Word or Custom Dialog Using OLE Automation

 * }

Q108686

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows, version 7.0

-

SUMMARY
You cannot directly define and display a Microsoft Word 6.0 dialog box through OLE Automation. However, you can run a WordBasic macro that displays a dialog box.

To display a Word dialog or user-defined dialog when using OLE Automation, activate Word for Windows and then run a WordBasic macro that includes the dialog statements.

WordBasic ToolsMacro Parameter Syntax
ToolsMacro [.Name = text], [.Run], [.Edit], [.Show = number], [.Delete], [.Rename], [.Description = text], [.NewName = text], [.SetDesc]

Examples
The following Visual Basic procedure activates Word for Windows and runs a global macro named "test".

Sub Command1_Click Dim wordobj As Object Set wordobj = CreateObject("Word.Basic") If wordobj.DocMaximize = True Then AppActivate "Microsoft Word - " + wordobj.[WindowName$] Else AppActivate "Microsoft Word" End If wordobj.ToolsMacro "test", True,, 1 End Sub NOTE: Word needs to have the focus (AppActivate) prior to running the global "test" macro.

The "test" macro can be used to display a Word dialog or a user-defined dialog. The following WordBasic macros serve as examples of each.

REM WordBasic macro named "Test"

REM This macro displays Word's FileSaveAs dialog

Sub MAIN Dim dlg As FileSaveAs GetCurValues dlg n = Dialog(dlg) If n = - 1 Then FileSaveAs dlg End Sub REM WordBasic macro named "Test"

REM This macro displays a user-defined dialog.

Sub MAIN Begin Dialog UserDialog 320, 144, "Microsoft Word" OKButton 210, 76, 88, 21 TextBox 29, 38, 160, 18, .TextBox1 CancelButton 212, 101, 88, 21 Text 29, 21, 35, 13, "Text", .Text1 End Dialog Dim dlg As UserDialog n = Dialog(dlg) End Sub WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.