ExcelAsyncUtil.QueueAsMacro from IExcelAddIn

452 views
Skip to first unread message

Kwint Me

unread,
Mar 26, 2018, 6:23:22 AM3/26/18
to Excel-DNA
Hi

I'm trying to call ExcelAsyncUtil.QueueAsMacro from Excel AddIn. Using ExcelDna 34.6, tried on 33.9 also
Some pseudocode:
public void AutoOpen() 
{
    //Some calls to ExcelIntegration.GetRegistrationInfo, ExcelIntegration.RegisterUnhandledExceptionHandler
    var externalComponent = new ExternalComponent();
    externalComponent.OnComplete += OnCompleteOnDifferentThread;
}

public void OnCompleteOnDifferentThread()
{
    ExcelAsyncUtil.QueueAsMacro(() =>
    {
        ExcelIntegration.RegisterXLL(_path);
    });
}

On ExcelAsyncUtil.QueueAsMacro I get "Error (InvalidOperationException) trying to run SyncMacro - Excel is shutting down. Queued macro execution abandoned."
I suspect that it's some timing/initialization issue as
This also doesn't work (writes same "Error (InvalidOperationException) trying..."):
public void AutoOpen()
{
    ExcelAsyncUtil.QueueAsMacro(() =>
    {
        MessageBox.Show("Test");
    });
}


Following works
public void AutoOpen()
{
            ThreadPool.QueueUserWorkItem(_ =>
            {
                Thread.Sleep(10000);
                ExcelAsyncUtil.QueueAsMacro(() =>
                {
                    MessageBox.Show("Test");
                });
            }, null);
}

Have anyone experienced/solved anything similar ?

Kwint Me

unread,
Mar 26, 2018, 8:12:10 AM3/26/18
to Excel-DNA
One important thing:
I'm getting the error only when I open excel file + I have addin loading by adding it to registry HKEY_CURRENT_USER\SOFTWARE\Microsoft\Office\15.0\Excel\options\OPEN
I'm not getting error when I just start excel from start menu.

But that could be also just a timing thing.

Govert van Drimmelen

unread,
Mar 28, 2018, 6:10:57 AM3/28/18
to exce...@googlegroups.com

I will try to have a look at this over the weekend.

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

Kwint Me

unread,
Mar 28, 2018, 11:32:59 AM3/28/18
to Excel-DNA
One more finding:
ExcelDnaUtil.Application returns null when I'm getting the error.
Waiting for this property to become not-null could be used as a workaround.

Govert van Drimmelen

unread,
Apr 6, 2018, 3:30:39 PM4/6/18
to Excel-DNA
I understand the problem now. If the first attempt to get the Application object is due to the QueueAsMacro running, it fails.
I plan to fix this in for the next version of Excel-DNA -  v. 0.35.

A workaround for now is to call ExcelDnaUtil.Application in your AutoOpen() before you call ExcelAsyncUtil.QueueAsMacro.

Thank you for reporting this.

-Govert

Govert van Drimmelen

unread,
Apr 22, 2018, 4:19:27 PM4/22/18
to Excel-DNA
I've made some updates to the QueueAsMacro and ExcelDnaUtil.Application code that should resolve this.

I would appreciate any help with testing, both for any regression and that this particular issue is fixed.
I've updated the source, and pushed to NuGet as ExcelDna.AddIn version 0.35.1-beta2.
Any feedback appreciated.

-Govert
Reply all
Reply to author
Forward
0 new messages