2

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 Answer 1

-1

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://learn.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

6
  • Thank you for responding. I'm using the code editor in Office online, however, I will try to test it locally in VS. As it stands, I can't get your example to work, and I can neither see it in the code sample you provided. I appreciate the help. Commented Mar 17, 2020 at 3:00
  • No manifest. Using Excel Online's new Code Editor. I'm not sure how to get to the displayDialogAsync method. I'll just use VS. Thanks. Commented Mar 17, 2020 at 20:19
  • What do you mean new Code Editor?
    – Raymond Lu
    Commented Mar 25, 2020 at 3:41
  • From the 'Automate' tab via Office Scripts. The one which gets enabled from Office.com > Admin > Settings > Office Scripts. Commented Apr 1, 2020 at 20:39
  • 1
    This is not Office Scripts Typescript compatible code. Commented Apr 13, 2022 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.