我試圖從5個ActiveX文本框中創建一個圖表,並將其放入我的工作表中。首先用戶輸入值,然後按下生成圖表的按鈕。Excel中的VBA:從ActiveX文本框創建圖表
這是我的方法,但它不起作用。它說,像「對象需要」
Private Sub CommandButton1_Click()
Dim arKurse(4) As Double
arKurse(0) = Conver.ToDouble(TextBox1.Text)
arKurse(1) = Conver.ToDouble(TextBox2.Text)
arKurse(2) = Conver.ToDouble(TextBox3.Text)
arKurse(3) = Conver.ToDouble(TextBox4.Text)
arKurse(4) = Conver.ToDouble(TextBox5.Text)
Dim oChtObj As ChartObject
Set oChtObj = ActiveSheet.ChartObjects.Add(Left:=445, Width:=385, Top:=10, Height:=245)
With oChtObj.Chart
.SeriesCollection.NewSeries
.SeriesCollection.Values = arKurse
.SeriesCollection.XValues = Array("1", "2", "3", "4", "5")
.ChartType = xlLine
.HasLegend = False
.HasTitle = True
.ChartTitle.Caption = "Chart"
End With
End Sub
它在哪裏說的錯誤?什麼是Conver.toDouble?你是在什麼地方定義的?爲什麼不使用'CDbl()'函數? – enderland
是你的文本框實際命名爲'TextBox1','TextBox2'等? – enderland