Avatar of iserschou
iserschou
 asked on

Excel throws Exception from HRESULT: 0x800A03EC

I am developing an Office 2003 SmartDocument application where Excel charts in the document are to be populated with data from code.
The following code handles the update of all Excel charts in the document:

            System.Globalization.CultureInfo ciOld = System.Threading.Thread.CurrentThread.CurrentCulture;
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            try
            {
                foreach (InlineShape objShape in wordDocument.InlineShapes)
                {
                    if (objShape.OLEFormat != null && objShape.OLEFormat.ClassType == "Excel.Chart.8")
                    {
                        objShape.Activate();
                        Microsoft.Office.Interop.Excel.Workbook objWorkBook = (Microsoft.Office.Interop.Excel.Workbook)objShape.OLEFormat.Object;
                        Microsoft.Office.Interop.Excel.Application objApp = objWorkBook.Application;
                        // Some code to manipulate the workbook...
                        objApp.Workbooks.Close();
                        objApp.Quit();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error: " + e.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                System.Threading.Thread.CurrentThread.CurrentCulture = ciOld;
            }

Executing the code as displayed above, throws an exception (Exception from HRESULT: 0x800A03EC) in the line containing 'objApp.Workbooks.Close();' for the first chart encountered.

Omitting the call will leave the chart selected in the document hiding the Actions Pane which is NOT intended.

Am I missing something - is there a workaround - suggestions are very welcome.
Programming

Avatar of undefined
Last Comment
Computer101

8/22/2022 - Mon
rmahesh


Could you try replacing

objApp.Workbooks.Close();

with

objWorkBook.Close();
iserschou

ASKER
I have already tried that with same result!
iserschou

ASKER
Found out this through MSDN news groups.

Instead of activating the Excell graph using the Activate method, it is activated using the DoVerb method. If supplied with the parameter wdOLEVerbHide, the graph can be populated with data and updated smoothly.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
theGhost_k8

try to get current applications object and then close it
applicationObject.activeworkbook.close
ASKER CERTIFIED SOLUTION
Computer101

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question