+ Reply to Thread
Results 1 to 7 of 7

Error 91: Object variable with block variable not set

Hybrid View

  1. #1
    Registered User
    Join Date
    12-27-2012
    Location
    edtr
    MS-Off Ver
    Excel 2003
    Posts
    16

    Error 91: Object variable with block variable not set

    This code opens an IE tab and puts the cell value from the sheet to the search bar and then click the go button Can someone please rectify the error it is coming in highlighted line:

    Option Explicit
    Sub getrent()

    Dim ele As Object
    Dim i As Long
    Dim IE As Object
    Dim FindHomes As Object

    ' Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")


    For i = 3 To 101

    ' You can uncoment Next line To see form results
    IE.Visible = False

    ' Send the form data To URL As POST binary request
    IE.Navigate "http://www.zillow.com/"

    ' Wait while IE loading...
    Do While IE.Busy Or _
    IE.readystate <> 4
    DoEvents
    Loop

    Set FindHomes = IE.document.getelementsbyname("Find Homes:")
    FindHomes.Item(0).Value = Workbooks("Book1").Sheets("Sheet1").Cell(i,5)--------> will this Cell reference work and the runtime error is also in this line, I think it's because of FindHomes

    IE.document.getElementById("GOButton").Click

    Next

    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Error 91: Object variable with block variable not set

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Last edited by Norie; 01-13-2013 at 12:42 PM.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    12-27-2012
    Location
    edtr
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Error 91: Object variable with block variable not set

    Sorry I am new here. Here it is again

    This code opens an IE tab and puts the cell value from the sheet to the search bar and then click the go button Can someone please rectify the error it is coming in highlighted line:

    Option Explicit
    Sub getrent()
    
    Dim ele As Object
    Dim i As Long
    Dim IE As Object
    Dim FindHomes As Object
    
    ' Create InternetExplorer Object
    Set IE = CreateObject("InternetExplorer.Application")
    
    
    For i = 3 To 101
    
    ' You can uncoment Next line To see form results
    IE.Visible = False
    
    ' Send the form data To URL As POST binary request
    IE.Navigate "http://www.zillow.com/"
    
    ' Wait while IE loading...
    Do While IE.Busy Or _
    IE.readystate <> 4
    DoEvents
    Loop
    
    Set FindHomes = IE.document.getelementsbyname("Find Homes:")
    FindHomes.Item(0).Value = Workbooks("Book1").Sheets("Sheet1").Cell(i,5)--------> will this Cell reference work and the runtime error is also in this line, I think it's because of FindHomes
    
    IE.document.getElementById("GOButton").Click
    
    Next
    
    End Sub

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Error 91: Object variable with block variable not set

    No problem, the code tags make it a lot easier to read.

    Anyway, the problem is that there are no elements on the page with the name 'Find Home:'.

    I think I know what you are trying to find but it must have some other name/id.

    Give this a try.
    Option Explicit
    
    Sub getrent()
    
    Dim ele As Object
    Dim i As Long
    Dim IE As Object
    Dim FindHomes As Object
    
        ' Create InternetExplorer Object
        Set IE = CreateObject("InternetExplorer.Application")
    
        For i = 3 To 101
    
            ' You can uncoment Next line To see form results
            IE.Visible = False
    
            ' Send the form data To URL As POST binary request
            IE.Navigate "http://www.zillow.com/"
    
            ' Wait while IE loading...
            Do While IE.Busy Or _
               IE.readystate <> 4
                DoEvents
            Loop
    
            Set FindHomes = IE.document.getelementsbyname("citystatezip")
    
            FindHomes.Item(0).Value = Workbooks("Book1").Sheets("Sheet1").Cells(i, 5)    '--------> will this Cell reference work and the runtime error is also in this line, I think it's because of FindHomes
    
            FindHomes.Item(0).form.submit
    
        Next
    
    End Sub
    Last edited by Norie; 01-13-2013 at 12:55 PM.

  5. #5
    Registered User
    Join Date
    12-27-2012
    Location
    edtr
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Error 91: Object variable with block variable not set

    Thanks a ton !! but somehow it is not able to open any IE window. It is just running and stopping.

  6. #6
    Registered User
    Join Date
    12-27-2012
    Location
    edtr
    MS-Off Ver
    Excel 2003
    Posts
    16

    Re: Error 91: Object variable with block variable not set

    Hey its working now, silly me, just had to change ievisible to true. Thanks a ton again

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Error 91: Object variable with block variable not set

    IE is opening, it's just not visible.

    That's because the code tells it to hide.
    ' You can uncoment Next line To see form results
            IE.Visible = False
    If you comment that line, or change False to True you should see an IE window.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1