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
ABC
1BuyersSellers
2UK2312
3US1232
4France3212
5Germany1232

<tbody>
</tbody>


New Workbook

ABC
1BuyersSellers
2UK4534
3US23445
4France234345
5Germany12345
6Italy 3434
7Spain4545

<tbody>
</tbody>


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
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,214,651
Messages
6,120,738
Members
448,988
Latest member
BB_Unlv

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