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?
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
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