错误1004 – 将值写入单元格

我的代码很简单,但似乎无法摆脱这个错误。 我已经尝试将string分配给一个variables,然后分配它,取消保护工作表,并将代码放入一个新的子函数。 该错误发生在第二个Analyze()

 Enum READYSTATE READYSTATE_UNINTIALIZED = 0 READYSTATE_LOADING = 1 READYSTATE_LOADED = 2 READYSTATE_INTERACTIVE = 3 READYSTATE_COMPLETE = 4 End Enum Dim html As HTMLDocument Sub Testing() Dim ie As InternetExplorer Set ie = New InternetExplorer ie.Visible = True ie.navigate "http://www.realclearpolitics.com/epolls/latest_polls/elections/" Do While ie.READYSTATE <> READYSTATE_COMPLETE Application.StatusBar = "Trying to reach RealClearPolitics.com" DoEvents Loop Set html = ie.document MsgBox html.DocumentElement.outerHTML Set ie = Nothing Application.StatusBar = " " Call Analyze End Sub Sub Analyze() Dim polldate As String polldate = "date" Worksheets("Sheet1").Activate Cells.Clear Worksheets("Sheet1").Cells(0, 0).Value = "Date" Worksheets("Sheet1").Cells(0, 1).Value = "Poll" Worksheets("Sheet1").Cells(0, 2).Value = "Page" End Sub 

Cells()必须具有以1开始的索引,而不是0

在使用Set ie = Nothing Call Analyze InternetExplorer对象之前,请先Call Analyze 。 将html设置为ie对象的文档,然后将其作为文档留给你。