0

I have an Excel Add-in using shared runtme which has some ribbon buttons and one of the ribbon button is used to open a dialog. However if user clicks this button frequantly, I am getting this error ""An internal error has occurred." and no page is loaded in dialog. Even right click on dialog does not show context menu which is usually shown when page is loaded. First image shows empty dialog opened.

enter image description here

Second Image shows debug breakpoint hit and error message I got in host taskpane. asyncResult.error.code has value "-2147467259". enter image description here

Any idea how to avoid this situation?

EDIT: code in ribbon event handler:

if(dialog)dialog.close();// close previously opened dialog. here dialog is reference of previously opened dialog if any
Office.context.ui.displayDialogAsync(urlp,
        { height: height, width: width, displayInIframe: true }, dialogCallbackIFrame);

event.completed();
Kashif
  • 85
  • 8

1 Answers1

0

You need to wait a bit until the previous dialog is closed. Try to add some delay before calling the displayDialogAsync method.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • I will try to add a delay, however as per documentation there is no way to know how much delay should be added and if previous dialog is not closed and next dialog open call will send 12007 error, in this case I called Open dialog function again as shown in 2nd image in question. and this approach is working if user does not click ribbon button so fast. – Kashif Feb 15 '23 at 12:44
  • 1
    True, but I've found that increasing the delay between attempts may help. – Eugene Astafiev Feb 15 '23 at 14:46
  • even though delay has not eliminated problem, but it has significantly reduced its occurrences. – Kashif Feb 16 '23 at 12:09