Strangely PeltierTech is where I 'borrowed' this bit of code from...
For Each ws In ActiveWorkbook.Worksheets
For Each oChart In ws.ChartObjects
For Each mySrs In oChart.Chart.SeriesCollection
mySrs.Formula = WorksheetFunction.Substitute(mySrs.Formula, "'Original Workbook Name.xlsm'", "'New Workbook Name.xlsx'")
Next
Next
Next ws
With regards your question 'does the workbook 'New Workbook Name.xlsx' actually exist?' I had been thinking about this, the answer is no because the code is designed to create a new workbook and save the file with the name of the new workbook but having said that, my understanding of the code above is that all it should be doing is changing the filename for the data series, as in from:
=SERIES(" Total Forecast",{"M1","M2","M3","M4","M5","M6","M7","M8","M9","M10","M11","M12"},'Original Workbook Name.xlsm'!My_Forecast,1)
to
=SERIES(" Total Forecast",{"M1","M2","M3","M4","M5","M6","M7","M8","M9","M10","M11","M12"},'New Workbook Name.xlsx'!My_Forecast,1)
before saving the file, so does 'New Workbook.xlsx actually need to exist before the file is saved? If the answer is yes, then does that mean the code needs to sit after
FName = Application.GetSaveAsFilename(InitialFileName:="C:\My Folder\My Report.xlsx", fileFilter:="Excel workbook (*.xlsx), *.xlsx")
On Error Resume Next: If FName <> False Then wb.SaveAs FName
If Err.Number <> 0 Then
Application.Dialogs(xlDialogSaveAs).Show
Err.Clear
End If
I'll experiment with some of your suggestions and let you know how I get on. Many thanks for all your very helpful suggestions. It feels as though the code is 95% there but I'm just missing one vital element... I just wish I know what that vital element was.
Bookmarks