-1
我想上的MS Excel website運行時錯誤91:對象變量或With塊變量未設置,例如,從MS辦公室網站
下面是代碼
給定提取使用宏從MS-Excel的圖形數據Sub GetChartValues()
Dim NumberOfRows As Integer
Dim X As Object
Counter = 2
' Calculate the number of rows of data.
NumberOfRows = UBound(ActiveChart.SeriesCollection(1).Values)
Worksheets("ChartData").Cells(1, 1) = "X Values"
' Write x-axis values to worksheet.
With Worksheets("ChartData")
.Range(.Cells(2, 1), _
.Cells(NumberOfRows + 1, 1)) = _
Application.Transpose(ActiveChart.SeriesCollection(1).XValues)
End With
' Loop through all series in the chart and write their values to
' the worksheet.
For Each X In ActiveChart.SeriesCollection
Worksheets("ChartData").Cells(1, Counter) = X.Name
With Worksheets("ChartData")
.Range(.Cells(2, Counter), _
.Cells(NumberOfRows + 1, Counter)) = _
Application.Transpose(X.Values)
End With
Counter = Counter + 1
Next
End Sub
此代碼中的錯誤在哪裏?
你調試代碼?它在哪一行發出錯誤? –
在這條線上 'NumberOfRows = UBound(ActiveChart.SeriesCollection(1).Values)' –
兩件事:你是否真的有一個標籤爲「ChartData」的工作表,你有一個活動的圖表?您需要在您提供的鏈接上遵循幾個步驟 –