這應該足以讓你開始。您需要根據自己的目的對其進行修改,但這會向您介紹您需要使用的屬性。
您如何構造「導出」數據最終取決於您。我舉例說明如何用Application.Transpose
函數將其寫入工作表,但您需要修改該部分以適應您的需求。
Sub DebugChartData()
Dim cht As ChartObject
Dim srs As Series
Dim lTrim#, rTrim#
Dim xValAddress As String
For Each cht In ActiveSheet.ChartObjects '## iterate over all charts in the active sheet
For Each srs In cht.Chart.SeriesCollection '## iterate over all series in each chart
'## The following given only to illustrate some of
' the properties available which you might find useful
' You will want to print these out to a worksheet, presumably,
' but I don't know how you intend to arrange these, on what
' sheet, etc, so I will leave that part up to you :)
Debug.Print srs.Name
Debug.Print vbTab & srs.Formula '# probably not so useful to you but I include it anyways.
'## You could parse the formula...
lTrim = InStrRev(srs.Formula, ",", InStrRev(srs.Formula, ",") - 1, vbBinaryCompare) + 1
rTrim = InStrRev(srs.Formula, ",")
xValAddress = Mid(srs.Formula, lTrim, rTrim - lTrim)
Debug.Print vbTab & xValAddress
'## , but that hardly seems necessary. You could convert the array of
' values/xvalues in to a delimited string and then do a text-to-columns on the data
Debug.Print vbTab & Join(srs.XValues, vbTab)
Debug.Print vbTab & Join(srs.Values, vbTab)
'## Or, you could use Application.Transpose to write out on a worksheet
'Qualify this with the appropriate Destination sheet, also make the destination variable
' as you accommodate multiple series/charts worth of data.
Range("A1").Resize(UBound(srs.XValues)) = Application.Transpose(srs.Values)
Next
Next
End Sub
您是否嘗試過手動操作並將操作記錄爲宏?當我這樣做時,我發現單個命令「ActiveChart.ApplyLayout(5)'做了許多魔術。也許類似的東西會爲你工作? – Floris
查看['Chart'](http://msdn.microsoft.com/zh-cn/library/office/aa213725(v = office.11).aspx)對象的方法,特別是'Chart.XValues' ,Chart.SeriesCollection(i).XValues'和Chart.SeriesCollection(i).YValues'。 – Chel