Set Source Range of charts in powerpoint

Ram_Patel

New Member
Joined
Nov 8, 2013
Messages
4
Hello forum,

I have a macro written in excel vba that updates the source links of charts in powerpoint to another excel file.
When running this, the source data uses the exact same range as in the previous spreadsheet (as expected).

Old Workbook
[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD]Buyers[/TD]
[TD]Sellers[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]UK[/TD]
[TD]23[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]US[/TD]
[TD]12[/TD]
[TD]32[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]France[/TD]
[TD]32[/TD]
[TD]12[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Germany[/TD]
[TD]12[/TD]
[TD]32[/TD]
[/TR]
</tbody>[/TABLE]


New Workbook

[TABLE="width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD][/TD]
[TD]Buyers[/TD]
[TD]Sellers[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]UK[/TD]
[TD]45[/TD]
[TD]34[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]US[/TD]
[TD]234[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]France[/TD]
[TD]234[/TD]
[TD]345[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Germany[/TD]
[TD]123[/TD]
[TD]45[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]Italy [/TD]
[TD]34[/TD]
[TD]34[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Spain[/TD]
[TD]45[/TD]
[TD]45[/TD]
[/TR]
</tbody>[/TABLE]


When updating the links, Italy and Spain would get missed out on the chart, as the source data range is exactly the same as before.

So my question is, how can I update the source data range?

Code:
Private Sub Tables()
     'Requires a reference to the Microsoft PowerPoint Library via the Tools - Reference menu in the VBE
    Dim ppApp As PowerPoint.Application
    Dim ppSlide As PowerPoint.Slide
    Dim SlideNumber As PowerPoint.SlideRange
      
'----------------------Slide 4------------------------------------
    On Error GoTo 0
    Sheets("Sheet1").Select
     
     'Look for existing instance
    On Error Resume Next
    Set ppApp = GetObject(, "PowerPoint.Application")
    On Error GoTo 0
     
     'Make the instance visible
    ppApp.Visible = True
    
    'Copy & Paste into correct place
    ppApp.ActiveWindow.View.GotoSlide (4)
    Set ppSlide = ppApp.ActiveWindow.View.Slide
    
    lstrow = Range("C1").End(xlDown).Row
    ppSlide.Shapes("Chart 9").Chart.SetSourceData Source:=Range("A1", "C" & lstrow) 'Code fails here

end sub

The code fails and gives a "run-time error 13, Type Mismatch". This is because the source data needs to be a string rather than a range.

Any help on this would be greatly appreciated

Thanks,
Ram
 

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top