Error 1004 - Writing a value to a cell

My code is very simple, but cannot get rid of this error. I tried to assign lines to a variable and then assign it, remove protection from the worksheet and put the code in a new subfunction. The error occurs in the second sub 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
+4
source share
2 answers

Cells () must have indices starting with 1 , not 0 .

+4
source

Place Call Analyzebefore you destroy an InternetExplorer object with Set ie = Nothing. Setting htmlthe ie object on the document, and then destruction, i.e. does not leave you with anything as a document.

0

All Articles