2
votes

My VSTO application has a ribbon which run VBA macro in active workbook, and a message dialog that displays the result of macro.

Usually, macro runs fine and the result correctly displayed in the dialog.

But once the macro contains ActiveWorkbook.Close, running macro will throw exception(0x800A9C68).

In my code, macro is called as c# - How to Call Excel VBA functions from VSTO Application addin - Stack Overflow suggested.

Any help will be appreciated! Thanks,

1
you should not be closing the workbook inside the macro - Jury Golubev
I think the problem is that your VSTO application instance accesses the macro in your workbook and waits that macro to finish but instead the workbook gets closed, so that macro never finishes and the access to that macro is lost immediately which causes the crash of that VSTO application. I think it's better to set a flag within the macro and close the workbook from VSTO if the flag is set. - Pᴇʜ

1 Answers

0
votes

It seems the workbook contains the VBA macro you call from an external application/add-in and expect to get any result. But VBA calls the Close which breaks the connection with an external applicaiton or add-in. Try to avoid using Close statements in the VBA macros.