这应该足以让您入门。您需要根据自己的目的对其进行修改,但这会向您介绍需要使用的属性。
如何构建“导出”数据最终取决于您。我举了一个例子,说明如何用函数将其写到工作表中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