HRESULT 0x800AC472 when populating excel range object

Add-in Express™ Support Service
That's what is more important than anything else

HRESULT 0x800AC472 when populating excel range object
 
Subscribe
Ming Chao




Posts: 20
Joined: 2019-01-23
Hi,

my app makes an api call and when data return it will populate an excel range object with a 2D array data using range.Value2 property. sometimes the API call take a few seconds. if end user is selecting the cell without releasing the mouse button or in cell edit mode and the app populating the Range object at the same time then HRESULT 0x800AC472 exception will be thrown. this all seems to be caused by the object browser is suspended as described the quote below. the post from MSDN suggested to keep trying in a loop until succeed. seems this is not ideal to introduce some boilerplate codes. is there's a better way to handle this error?


you are getting the VBA_E_IGNORE error that Excel will return when you try to invoke the object model when the property browser is suspended. This will happen around user edits to ensure that things don't get out of whack with automation slipping in in the middle. What Excel is telling you is simply that it isn't ready to handle your call at the time you are making it.

https://social.msdn.microsoft.com/Forums/vstudio/en-US/ee0bdafa-6d6d-4025-b7cb-5537d79dbc48/writing-data-from-c-to-excel-interrupted-by-opening-excel-help-or-options-window?forum=csharpgeneral
Posted 21 Oct, 2019 15:06:19 Top
Andrei Smolin


Add-in Express team


Posts: 16673
Joined: 2006-05-11
Hello Ming,

I suggest that you check How to check programmatically if the user is editing an Excel cell. Then, make sure you use the Excel object model on the main thread only and your code has no Doevents() call.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 22 Oct, 2019 03:00:47 Top
Ming Chao




Posts: 20
Joined: 2019-01-23
Hi Andrei,

thank you for your reply. im able to resolve my issue by polling ExcelApp.Interactive in a do-while loop. im using a Task.Delay() inside a catch block to wait indefinitely. are there any side affects by doing so in the main thread. below is my code snippet of my implementation.

public async void writeData()
{
    ...
    await SetInteractive(false);
    range.Value2 = Get2DArray(); //2D array
    await SetInteractive(true);
    ...
}

private async Task SetInteractive(bool interactive)
{
    do
    {
        try
        {
            excelApp.Interactive = interactive;
        }
        catch (Exception e)
        {
            await Task.Delay(1000);
        }
    } while (excelApp.Interactive != interactive);
}
Posted 22 Oct, 2019 10:50:48 Top
Andrei Smolin


Add-in Express team


Posts: 16673
Joined: 2006-05-11
Hello Ming,

I would check how this construct behaves when you close Excel.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 23 Oct, 2019 04:55:55 Top
Ming Chao




Posts: 20
Joined: 2019-01-23
thank you Andrei. my code could cause excel process to hang after closing excel. we decided to let end user to handle the situation.
Posted 25 Oct, 2019 15:49:30 Top
Andrei Smolin


Add-in Express team


Posts: 16673
Joined: 2006-05-11
Welcome!

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 28 Oct, 2019 04:07:10 Top