Hi all,
I have a huge PowerPoint presentation, most slides with charts. I need to change the text within the charts - usually the text repeats itself in all charts. Instead of manually, opening the chart data and pasting the new text, I wrote the following syntax. All components work, except for the Replace line:
I get a "Run-time error '9': Subscript out of range" message
What am I doing wrong?
Thanks!
Sub TranslateCharts()
Dim sLang1 As String, sLang2 As String
Dim sh As Shape
On Error Resume Next
Set ppApp = GetObject(, "PowerPoint.Application")
If Err.Number <> 0 Then
Set ppApp = CreateObject("PowerPoint.Application")
End If
Err.Clear
On Error GoTo 0
ppApp.Visible = True
Set myPresentation = ppApp.Presentations.Open("---path/filename appear here---")
ChangeCharts "XXX", "YYY"
End Sub
Sub ChangeCharts(sLang1 As String, sLang2 As String)
Dim oSld As Object
Dim oChart As Chart
Dim oShp As Shape
Dim oChartData As ChartData
For Each oSld In myPresentation.Slides
oSld.Select
For Each oShp In oSld.Shapes
oShp.Select
If oShp.HasChart Then
Set oChart = oShp.Chart
oChart.Select
Set oChartData = oChart.ChartData
oChartData.Activate
oChartData.Workbook.worksheets("Sheet1").Range("A1:F10").Select ' works fine up to this line - data table opens, range is highlighted
' this is the command line for which I get the error:
oChartData.Workbook.worksheets("Sheet1").Range("A1:F10").Replace What:=sLang1, Replacement:=sLang2, LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
oChart.ChartData.Workbook.Close
End If
Next
Next
End Sub