When Microsoft Office Word is used, the user input dialog box is displayed. Although you can create your own dialog box, you may also want to use the built-in dialog box in word, which is published in the dialogs set of the Application object. This allows you to access more than 200 built-in dialogs, which are represented in enumeration.
Applicable:The information in this topic applies to document-level projects and application-level projects in Word 2013 and word 2010. For more information, see the functions provided by office applications and projects.
Show dialog box
To display the dialog box, use one of the wdworddialog enumerated values to create a dialog object, which indicates the dialog box to be displayed. Then, call the show method of the dialog object.
The following code example shows how to display the "open" dialog box. To use this example, run it from the thisdocument or thisaddin class in the project.
C # VB Replication
Word.Dialog dlg = Application.Dialogs[Word.WdWordDialog.wdDialogFileOpen];dlg.Show();
Access the members of the dialog box that can be used by later binding
Some attributes and methods of the dialog box in word can only be used through later binding. Open At the option strict position of the Visual Basic project. You must use reflection to access these members. For more information, see post-binding in office solutions.
The following code example shows how to use the name attribute of the file opened dialog box in option strict or visual basic projects for. NET Framework 4 or. NET Framework 4.5 in Visual C. To use this example, run it from the thisdocument or thisaddin class in the project.
C # VB Replication
dynamic dialog = Application.Dialogs[Word.WdWordDialog.wdDialogFileOpen];dialog.Name = "Testing";dialog.Show();MessageBox.Show(dialog.Name);
The following code example shows how to use reflection to open the option strict position of the name attribute in the open dialog box of the file in Visual Basic. To use this example, run it from the thisdocument or thisaddin class in the project.
VB Replication
Dim dlg As Word.Dialog = Application.Dialogs(Word.WdWordDialog.wdDialogFileOpen)Dim dlgType As Type = GetType(Word.Dialog)‘ Set the Name property of the dialog box.dlgType.InvokeMember("Name", _ Reflection.BindingFlags.SetProperty Or _ Reflection.BindingFlags.Public Or _ Reflection.BindingFlags.Instance, _ Nothing, dlg, New Object() {"Testing"}, _ System.Globalization.CultureInfo.InvariantCulture)‘ Display the dialog box.dlg.Show()‘ Show the Name property.MessageBox.Show(dlgType.InvokeMember("Name", _ Reflection.BindingFlags.GetProperty Or _ Reflection.BindingFlags.Public Or _ Reflection.BindingFlags.Instance, _ Nothing, dlg, Nothing, _ System.Globalization.CultureInfo.InvariantCulture))