Displaying a Word or Custom Dialog Using OLE Automation

Last reviewed: February 6, 1998
Article ID: Q108686
The information in this article applies to:
  • Microsoft Word for Windows, versions 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, 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.

REFERENCES

"Microsoft Word Developer's Kit," version 6.0, Microsoft Press, 1993, pages 179-180


KBCategory: kbmacro
KBSubcategory:
Additional query words: 6.0 visual basic appactivate word6
6.0a 6.0c 7.0 word95 word7 winword user defined
Keywords : kbole kbmacro
Version : 6.0 6.0a 6.0c 7.0
Platform : WINDOWS


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 6, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.