Excel VBA - Programmatically change chart's source?
I've got this Excel document which contains several charts which target Named Ranges that are all predefined. The problem is, the reference the chart needs have to include the name of the document for some reason. I've managed to add the filename of the document in the sheet. But I cannot target this cell directly when assigning the source of the chart.
So, when I edit the chart and select the source, it looks like this:
='MyExcelDocument.xlsm'!Graphs_TotCost
For some reason Excel doesn't understand when I target the cell that contains the filename. So I开发者_如何转开发'll probably have to do this via a macro by first defining a string variable, assigning the document name to that string. And then assign the completed string combined with Graphs_TotCost
. So, how do I select a chart that's in Sheet3 and change the source of that chart using a macro?
You can change the source of a graph with this kind of statement:
Charts("Chart1").ChartWizard Source:="Graphs_TotCost"
You could also probably use the SetSourceData
method of the Chart object.
精彩评论