none
Redirect Chart Obejct in PowerPoint pptx From One Excel Range to Another RRS feed

  • Question

  • Hello.

    I use PowerPoint VSTO add-in to redirect charts to another Excel source.

    I fill some range in Excel file, create a chart and copy it in PowerPoint presentation. Then I find chart just copied and execute the following code:

    oShape.Chart.SetSourceData(source, Type.Missing);
    oShape.Chart.Refresh();
    
    

    Where "source" variable looks like this

    string source = @"='C:\Path\To\File\[MyBOOK.xlsx]Sheet1'!$L$16";
    

    It works only if I have both PowerPoint and Excel applications in opened state from copiyng chart till executing SetSourceData method. This way doesn't work if I close Excel and even if I then will reopen Excel again. Closing and opening PowerPoint also breaks a work.

    How can I make Chart.SetSourceData() method works in case of closing Excel or PowerPoint? Or is there another way to redirect PowerPoint chart to another Excel source? Maybe through OpenXML api?

     

    Thanks, Mikhail.

     

    Friday, June 17, 2011 10:31 AM

Answers

  • Hm, looks like I've found a solution. Before we call SetSorceData() we should Activate linked Excel Workbook:

    oShape.Chart.ChartData.Activate();
    

    After this linked Excel document opens and shows itself on the screen. And we can get access to it through oShape.Chart.ChartData.Workbook property. For example we are able to close Excel after using SetSourceData() method.

     

    Hope this will be useful for anybody =)

    Mikhail.

    • Marked as answer by Bruce Song Thursday, June 23, 2011 11:43 AM
    Friday, June 17, 2011 2:16 PM

All replies

  • Hm, looks like I've found a solution. Before we call SetSorceData() we should Activate linked Excel Workbook:

    oShape.Chart.ChartData.Activate();
    

    After this linked Excel document opens and shows itself on the screen. And we can get access to it through oShape.Chart.ChartData.Workbook property. For example we are able to close Excel after using SetSourceData() method.

     

    Hope this will be useful for anybody =)

    Mikhail.

    • Marked as answer by Bruce Song Thursday, June 23, 2011 11:43 AM
    Friday, June 17, 2011 2:16 PM
  • Hi Mikhail,

    Glad to hear that you have resolved your problem and share it with us. You are welcome.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 22, 2011 10:32 AM