Re: XlCall.TryExcel with XlCall.xlfDialogBox is unreliable on Excel 2013

436 views
Skip to first unread message

Govert van Drimmelen

unread,
Mar 19, 2013, 8:13:39 AM3/19/13
to Excel-DNA
Hi,

Most likely the issue has to do with Excel 2013's change to a single-
document interface. This affects what the 'parent' of a window might
be, perhaps interfering with the dialog display. (For example, there
is a bad interaction with Excel-DNA whereby the Application object is
sometimes not retrieved correctly. However, if this were the cause of
your problem, the macro would not have run at all.)

You say the return value is XlReturnFailed in the problem case. This
implies that the API call went through, but failed in Excel. It would
help to confirm that other API calls are fine in the same context.
Maybe you can add something like XlCall.Excel(XlCall.xlcAlert, "Things
went wrong...") in the failing case. That would confirm that Excel is
not showing the dialog, but is able to process C API calls.

If so, it is a tricky problem, since it might indicate that the bug is
in Excel itself, and not in Excel-DNA. To confirm this, we'd need to
implement the add-in as a native C .xll, and if we are able to
reproduce in that case we can report to Microsoft as a bug.


I know that's not very helpful, though.

-Govert



On Mar 19, 7:48 am, Koustubh Moharir <koustubhmoha...@gmail.com>
wrote:
> I am trying to show a simple dialog with the C API from a Ribbon button
> click with RunTagMacro. This works as expected on Excel 2007. On Excel 2013
> (my development environment), it sometimes works and sometimes doesn't.
> TryExcel sometimes returns XlReturnFailed. I have attached a minimal sample
> dna file that reproduces the problem. Click on the button under My Tab on
> the ribbon. When it works it shows a simple dialog. When it fails, nothing
> happens.
>
> Can someone give me pointers on how I should investigate this further? Is
> it possible to get any further diagnostic output for the reason of the
> failure?
>
>  TestDialog.dna
> 1KViewDownload

Govert van Drimmelen

unread,
Mar 19, 2013, 9:32:39 AM3/19/13
to Excel-DNA
Hi,

Thanks for writing back with more details.

* I've yet to try your code under Excel 2013 (it seemed to work fine
under my Excel 2010).

* Can you give some indication of how often the xlfDialogBox call
fails - is it about 50% if the button presses, more often or rarely?
Does it matter which workbook is active when you press the button,
e.g. the first workbook in the Excel session might behave differently?

* Instead of triggering the macro from a ribbon, could you start it
directly from the Alt+F8 dialog box (you'll have to type in your macro
name, then the 'Run' button will become available)? This setting
differs in that it removes the ribbon, and Excel-DNA's RunAsMacro
helper from the equation.

* I think there is a dialog sample somewhere in the Excel XLL SDK.
I'll try to compile it into a working .xll and post it somewhere
online for you to test.

-Govert


On Mar 19, 3:19 pm, Koustubh Moharir <koustubhmoha...@gmail.com>
wrote:
> Hi Govert,
>
> Firstly, thanks for replying and for your incredibly useful work!
>
> I tried your suggestion by adding the following code
>
> if (callResult == XlCall.XlReturn.XlReturnFailed)
>        XlCall.Excel(XlCall.xlcAlert, "Things went wrong...");
>
> Now I either get my intended dialog or the alert. Always. So the other
> calls are indeed going through correctly.
>
> I also tried putting the call in an infinite loop until it succeeds. Most
> times, it succeeds within 5 attempts, but if it doesn't, it gets stuck in
> the infinite loop. If I exit the loop manually from the debugger, it
> typically succeeds the next time within 5 attempts.
>
> I can't think of a reason why the dialog would fail intermittently but the
> alert would succeed (since they both do similar things).
>
> I don't have the necessary skills to implement a native C xll at this
> point. So I might resort to setting up a timer event on Excel's UI thread
> and retrying the call there.
>
> Many thanks for your support.

Govert van Drimmelen

unread,
Mar 19, 2013, 5:08:57 PM3/19/13
to Excel-DNA
Hi,

I've uploaded the Generic.xll from the Excel 2013 Preview SDK. You can
find it here: https://s3.amazonaws.com/share.excel-dna.net/GENERIC.xll

I just ran make.bat from a VS 2012 command prompt, so I'm not sure
whether it needs a C/C++ runtime. If it fails to load, I can make
another version.

This add-in has a macro called "fDialog" which shows an xlfDialogBox
dialog (it pops up twice). Also via the Add-Ins->Generic->Dialog...
button

If this also gives problems under your Excel 2013, then we have an
Excel bug. If not, we have to backtrack a bit and test further.

Could you have a look?

(In practical terms, are there reasons for you not to make a Windows
Forms or WPF form instead? One issue might be the RefEdit control...)

Thanks,
Govert


On Mar 19, 10:22 pm, Koustubh Moharir <koustubhmoha...@gmail.com>
wrote:
> Hi Govert,
>
> There doesn't seem to be any pattern to when it fails - sometimes it works
> several times in succession and sometimes it fails several times in
> succession too. In 100 attempts it succeeded 43 times.
>
> It fails both on my home PC and office PC (both have 32 bit Office 2013 on
> 64 bit Windows 8).
>
> Running from the ribbon (button click) or from the Macros dialog (Alt F8)
> makes no difference. Running with no workbook (just double-click on the
> add-in), from the first workbook, subsequently opened workbooks or closing
> the first workbook makes no difference either.
>
> I will try to find the dialog sample from the SDK as soon as I get time.
>
> Thanks.

Govert van Drimmelen

unread,
Mar 20, 2013, 5:31:48 AM3/20/13
to Excel-DNA
Hi,

Thanks for checking and confirming that this looks like an Excel bug.

Do you have a corporate channel (a Microsoft account manager or
someone) to report this formally?

Otherwise, the best place is probably the "Excel for Developers" forum
here: http://social.msdn.microsoft.com/Forums/en-US/exceldev

If one is persistent, it seems some of the moderators can get issues
properly reported inside Microsoft.

-Govert


On Mar 20, 12:35 am, Koustubh Moharir <koustubhmoha...@gmail.com>
wrote:
> Hi Govert,
>
> The add-in loads but has the same problem, the Dialog command only works
> sometimes. Via the macro, it almost never works (works about once in 10
> attempts).
>
> Looks like an excel bug then.
>
> Thanks for your support.

CSharp Dummy

unread,
Mar 11, 2014, 9:34:03 AM3/11/14
to exce...@googlegroups.com
Yes I am having the same problem.

The code throws an error and you need execute several times before it takes.
In debugging mode it seems to work a bit better.
You can't build a loop around the call since it seems to worsen the problem and never executes.

Is there any work around? Otherwise code that works in EXCEL 2010 will stop working in 2013.


On Wednesday, March 20, 2013 4:10:05 PM UTC-4, Koustubh Moharir wrote:
Hi Govert,

I don't think I have a corporate channel. I will check.

I will post it on the forum in any case.

Thanks.

Koustubh Moharir

unread,
Mar 11, 2014, 9:54:57 AM3/11/14
to exce...@googlegroups.com
CSharp Dummy,

I don't know of a workaround and I have given up on the idea which was only attractive for the RefEdit control. The RefEdit sometimes it shows the wrong sheet (even under Excel 2007 where it loads properly), making the whole approach useless.

I think someone has an implementation of a RefEdit control on CodeProject that uses sheet selection changed events. I intend to look at it myself in a couple of weeks and will post back when I do so.

Regards,
Koustubh

Stanislav

unread,
Feb 13, 2015, 11:25:41 AM2/13/15
to exce...@googlegroups.com
I tested with Excel 2013 SP1 after coinsiding with problems of Excel 2013 and it works well. Seems that the bug was fixed in SP1.

Govert van Drimmelen

unread,
Feb 16, 2015, 4:21:39 PM2/16/15
to exce...@googlegroups.com
Ah - that's good to know.
Thank you for posting.

-Govert
Reply all
Reply to author
Forward
0 new messages