Use the built-in dialog box in Word programmatically

Source: Internet
Author: User

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))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.