none
Chart.SetElement returns Error HRESULT E_FAIL RRS feed

  • Question

  • Hi,

    After security update "Security Update for Microsoft Excel 2013 (KB3085502)"

    The following error is thrown in Chart creation:

    Failed to Open View Graph: Error HRESULT E_FAIL has been returned from a call to a COM component.

       at Microsoft.Office.Interop.Excel._Chart.SetElement(MsoChartElementType Element)

       at Classes.clsControlMethods.AddPivotChart(ViewUI ViewUI, ViewGraphPage GraphPage, ViewGraphChart Chart, Int32 chartLeft, Int32 chartTop, Int32 chartWidth, Int32 chartHeight)

       at Classes.clsControlMethods.OpenViewGraph(Int32 ViewId, Int32 GraphPageSeq, Boolean ForceRefresh)

    and when we uninstalled the update every thing worked fine.

    I want to know scenarios when HResult E_Fail occurs

    Wednesday, September 16, 2015 10:29 AM

Answers

  • Hi Edward,

    I have found the reason why it was failing to create chart.

    Reason for Chart Issue:

     chart.SetSourceData(pivotTable.DataBodyRange);

    Here the pivotTable.DataBodyRange.Value was Null

    The pivot table containing data series had formula. I think it was unable to evaluate those column values.

    Fix I found:
    I forced it to calculate the formula values.
       

    Code I have added:
    I have added below code before chart creation.

    pivotTable.ManualUpdate = false; 
    ThisWorkbook._app.Calculate();// force calculation

    Thanks

    • Marked as answer by Karthan Vijay Tuesday, September 29, 2015 6:16 AM
    Tuesday, September 29, 2015 6:05 AM

All replies

  • Failed to Open View Graph: Error HRESULT E_FAIL has been returned from a call to a COM component.


       at Microsoft.Office.Interop.Excel._Chart.SetElement(MsoChartElementType Element)

       at ROCEPlanningSuite.Classes.clsControlMethods.AddPivotChart(ViewUI ViewUI, ViewGraphPage GraphPage, ViewGraphChart Chart, Int32 chartLeft, Int32 chartTop, Int32 chartWidth, Int32 chartHeight)

       at ROCEPlanningSuite.Classes.clsControlMethods.OpenViewGraph(Int32 ViewId, Int32 GraphPageSeq, Boolean ForceRefresh)

    Wednesday, September 16, 2015 6:02 AM
  • Hello Karthan,

    VSTO doesn't provide anything for that. I'd suggest asking host-specific questions on the appropriate forum thread (Excel for Developers) or just use the general dev forum instead.

    What code exactly do you have? Where and when do you run it?

    Wednesday, September 16, 2015 6:14 AM
  • Hi Karthan,

    >> Chart.SetElement returns Error HRESULT E_FAIL

    I made a test with the vba code below under Office 2013 with KB3085502, but I failed to reproduce your issue. It worked correctly at my side.

    Sub ChartElement()
    ActiveChart.SetElement (MsoChartElementType.msoElementChartTitleAboveChart)
    End Sub

    I suggest you update your office to latest version, my Office version is Excel 2013 (15.0.4753.1000) MSO (15.0.4569.1506).

    In addition, I suggest you test your code at other PCs with this kb to check whether it could be reproduced, if it could be reproduced, you could share us your simple code and system version, and then we could test at our side to check whether it could be reproduced.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, September 17, 2015 6:20 AM
  • Hi Edward,

    I have found the reason why it was failing to create chart.

    Reason for Chart Issue:

     chart.SetSourceData(pivotTable.DataBodyRange);

    Here the pivotTable.DataBodyRange.Value was Null

    The pivot table containing data series had formula. I think it was unable to evaluate those column values.

    Fix I found:
    I forced it to calculate the formula values.
       

    Code I have added:
    I have added below code before chart creation.

    pivotTable.ManualUpdate = false; 
    ThisWorkbook._app.Calculate();// force calculation

    Thanks

    • Marked as answer by Karthan Vijay Tuesday, September 29, 2015 6:16 AM
    Tuesday, September 29, 2015 6:05 AM