How can I create a message box with user responses in Office JavaScript API?

Viewed 1043

I'm looking for a way to create a message box using the Office JavaScript API. I'm creating a small project and step #1 is to ask the user a yes/no question.

There is a [message box] version using VBA (among other languages) which lets you set the message, buttons, title, and track the response. I need this kind of user interaction for a project I'm working on but can't seem to find anything equivalent in the api. Specifically, I need to be able to ask the user a question at run-time and gather their response. An alternative would be to have a notion of 'settings' for the project.

Is what I'm looking for even possible?

1 Answers

Yes, this is possible, To open a dialog box,you could call the displayDialogAsync method and passes to it the URL of the resource that you want to open.

var dialog;
Office.context.ui.displayDialogAsync('https://myDomain/myDialog.html', {height: 30, width: 20},
    function (asyncResult) {
        dialog = asyncResult.value;
        dialog.addEventHandler(Office.EventType.DialogMessageReceived, processMessage);
    }
);

you can find the document at https://docs.microsoft.com/en-us/javascript/api/office/office.ui?view=word-js-preview#displaydialogasync-startaddress--options--callback-

Code sample can be found at https://github.com/OfficeDev/Excel-Add-in-JavaScript-SalesTracker

Related