none
PowerPoint 2010 add in Charts issue RRS feed

  • Question

  • Hello,

    Please let me know or direct me to the right forum if i am posting it at a wrong place.

    i am working on add in VSTO for PowerPoint which has already been developed, but i am facing an issue when dynamically creating charts.

    This add in uses Shapes.AddChart() function to draw a chart on the current slide. But when this method is called it opens an excel file containing chart data. I want to prevent this excel file from opening as the graph is being drawn through code.

    Is there a way that i can prevent excel from being opened, or at least run excel in the background so it is not shown?

    Also if i closes this excel sheet through code it also closes other opened excels which are not related.

    Can i run an excel file separatly and tell the Shapes.AddChart() method to use this excel file/workbook instead of creating a new one.

    I am using the code written @

    http://msdn.microsoft.com/en-us/library/office/gg185648%28v=office.14%29.aspx

    Any help in this regard is much appreciated.

    Thanx

    Friday, February 8, 2013 2:57 PM

Answers

  • Hi Leo

    <<Can i run an excel file separatly and tell the Shapes.AddChart() method to use this excel file/workbook instead of creating a new one.>>

    Yes. You'll want the Chart to be a Chart sheet (not a chart embedded on a worksheet) and it should be the first sheet in the workbook. Then this works (tested in PowerPoint 2010):

    ActivePresentation.Slides(2).Shapes.AddOLEObject FileName:="C:\Test\SampleChart.xlsx"


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, February 8, 2013 4:37 PM
    Moderator
  • <<Could you suggest any workaround based on your experience for the Shapes.AddChart() to bypass its normal behaviour for opening excel?>>

    I know of no way to avoid this. It's by design. I made the same complaint during the 2007 beta and that was the answer I got.

    The only alternative I know of, theoretically, would be to create the necessary Word Open XML in the OPC flat package format and use Range.InsertXML to "drop" it into Word. But I don't know if this would actually work. If you don't have extensive experience with the Open XML file format and programming XML it would take much longer to develop than Shape.AddOLEObject.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 11, 2013 7:01 AM
    Moderator

All replies

  • Hi Leo

    <<Can i run an excel file separatly and tell the Shapes.AddChart() method to use this excel file/workbook instead of creating a new one.>>

    Yes. You'll want the Chart to be a Chart sheet (not a chart embedded on a worksheet) and it should be the first sheet in the workbook. Then this works (tested in PowerPoint 2010):

    ActivePresentation.Slides(2).Shapes.AddOLEObject FileName:="C:\Test\SampleChart.xlsx"


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, February 8, 2013 4:37 PM
    Moderator
  • Hi Cindy,

    Thanx for your reply.

    Actually i want to do something like that for Shapes.AddChart() because the add in i am working on is already developed and is using Shapes.AddChart() so the charts can be later editable also if i now start changing the code to make it compatible for Shapes.AddOLEObject  it will take me some 10-12 days :( because they are being extensively used.

    Could you suggest any workaround based on your experience for the Shapes.AddChart() to bypass its normal behaviour for opening excel?

    Thanx in advance.

    Monday, February 11, 2013 6:27 AM
  • <<Could you suggest any workaround based on your experience for the Shapes.AddChart() to bypass its normal behaviour for opening excel?>>

    I know of no way to avoid this. It's by design. I made the same complaint during the 2007 beta and that was the answer I got.

    The only alternative I know of, theoretically, would be to create the necessary Word Open XML in the OPC flat package format and use Range.InsertXML to "drop" it into Word. But I don't know if this would actually work. If you don't have extensive experience with the Open XML file format and programming XML it would take much longer to develop than Shape.AddOLEObject.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 11, 2013 7:01 AM
    Moderator
  • I believe then i have to either shift it to Shape.AddOLEObject or inform the stakeholders that it is there by design(form microsoft) if they can buy my crap :(

    Anyways thanx for your help.

    Monday, February 11, 2013 7:16 AM
  • HI Leo

    Well, it's not "crap", it's the truth... If you want "proof", open a paid support incident with Microsoft to get it confirmed.


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, February 11, 2013 8:46 AM
    Moderator
  • Hi Cindy

    I know that its Microsoft official response "that the behavior is there by design" by visiting couple of other forums/posts. All i was hoping that someone with extensive experience in PowerPoint/Office development could figure out a solution.

    Anyways you have tried to help a lot and i am really grateful to you.

    Monday, February 11, 2013 9:04 AM