Link to home
Start Free TrialLog in
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.
Avatar of rmahesh
rmahesh


Could you try replacing

objApp.Workbooks.Close();

with

objWorkBook.Close();
Avatar of iserschou

ASKER

I have already tried that with same result!
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.
Avatar of theGhost_k8
try to get current applications object and then close it
applicationObject.activeworkbook.close
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial