How to: Use Built-In Dialog Boxes in Word
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

How to: Use Built-In Dialog Boxes in Word


Some code examples in this topic use the this or Me keyword or the Globals class in a way that is specific to document-level customizations, or they rely on features of document-level customizations such as host controls. These examples can be compiled only if you have the required applications installed. For more information, see Features Available by Product Combination.

When working with Microsoft Office Word 2003, there are times when you need to display dialog boxes for user input. Although you can create your own, you might also want to take the approach of using the built-in dialog boxes in Word, which are exposed in the Dialogs collection of the Application object. This allows you to access over 200 of the built-in dialog boxes, which are represented as enumerations.

To use a built-in dialog box

  1. Assign one of the WdWordDialog enumerations to the variable to specify the Word dialog box you want.

    Word.Dialog dlg = Application.Dialogs[Word.WdWordDialog.wdDialogFileNew];
  2. Once you create the Dialog variable, you can make use of its methods.

    object timeOut = 0;
    dlg.Show(ref timeOut);

To access dialog box members

  1. Get the dialog box type and set the Name property to Testing.


    Interactions with built-in Word dialog boxes occur through late binding, so if you have Option Strict set to On or you use C#, you cannot access members of the dialog boxes directly. You must use the Reflection libraries to access dialog box members.

    Word.Dialog dlg = Application.Dialogs[Word.WdWordDialog.wdDialogFileOpen];
    System.Type dlgType = typeof(Word.Dialog);
    // Set the Name property of the dialog box.
        System.Reflection.BindingFlags.SetProperty | 
            System.Reflection.BindingFlags.Public | 
        null, dlg, new object[] {"Testing"},
  2. Show the dialog box, and then show the Name property in a message box.

    // Display the dialog box.
    dlg.Show(ref missing); 
    // Show the Name property.
        System.Reflection.BindingFlags.GetProperty |
            System.Reflection.BindingFlags.Public |
        null, dlg, null,

See Also

© 2015 Microsoft