Office Add-in Dialog API Example
Applies to: Word 2016
Learn how to open popup dialogs in Office Add-ins with the Dialog API's
Office.context.ui.displayDialogAsync method and also the use of add-in commands. While the sample uses Word you can easily use the same code for other Office applications including Excel, PowerPoint and Outlook.
The first command uses the ShowTaskpane action and then an HTML button inside the taskpane to trigger a dialog from within a taskpane. The second command uses the ExecuteFunction action to display a dialog directly.
Set up the project
With Visual Studio
- Clone this repo and then open the SimpleDialogSample.sln in Visual Studio.
- Press F5 to build and deploy the sample add-in. Word launches and the add-in will be installed.
Without Visual Studio
- Clone this repo.
- Deploy the SimpleDialogSampleWeb folder in your web server of choice. Make sure it supports httpS.
- Modify the \SimpleDialogSample\SimpleDialogSample.xml file so that all URLs point to your web server (replace the ~placeholders)
- Create a network share, or share a folder to the network.
- Place a copy of the SimpleDialogSample.xml manifest file into the shared folder.
- Launch Word and open a document.
- Choose the File tab, and then choose Options.
- Choose Trust Center, and then choose the Trust Center Settings button.
- Choose Trusted Add-ins Catalogs.
- In the Catalog Url field, enter the network path to the folder share that contains SimpleDialogSample.xml, and then choose Add Catalog.
- Select the Show in Menu check box, and then choose OK.
- A message is displayed to inform you that your settings will be applied the next time you start Microsoft Office. Close Word.
- Restart Word and open a Word document.
- On the Insert tab in Word 2016, choose My Add-ins.
- Select the SHARED FOLDER tab.
- Choose Simple Dialog Exampmle, and then select OK.
- On the Home ribbon is a new group called Sample Group with a buttons labeled Dialog from Task Pane and Dialog from Function.
Try out the sample
- Click the Dialog from Task Pane button and a task pane opens.
- Click Pick a number! to open a dialog.
- On the dialog, click one of the number buttons. The number you chose appears in a message banner at the top of the task pane and the dialog closes.
- Click Pick a number! again.
- Click it again immediately to see the error when a user tries to open more than one dialog.
- Click the X button in the upper right of the dialog to see a sample message in the task pane that responds to the user closing the dialog.
- Close the task pane.
- On the ribbon, click the Dialog from Function button. A short message appears in the document. You may have to drag the dialog out of the way to see it.
- On the dialog, click one of the number buttons. The number you chose appears in the document and the dialog closes.
- Click the Dialog from Function button again.
- Click the X button in the upper right of the dialog to see a sample message in the document that responds to the user closing the dialog.
The following samples also make use of the dialog API for authentication scenarios:
- PowerPoint Add-in in Microsoft Graph ASP.Net Insert Chart
- Office Add-in Auth0
- Excel Add-in ASP.NET QuickBooks
- Office Add-in Server Authentication Sample for ASP.net MVC