locked
Run-time error '91': Object variable or With block variable not set RRS feed

  • Question

  • I'm attempting to write a sub that will open IE and search a website for a particular value (set to Biloxi, MS for testing purposes).  However, I'm encountering a run-time 91 error and none of the previous posts I've seen seem to hold the answer.  Here's my code so far:

    Sub SearchRealtorDotCom()
    
    Dim ieApp As New SHDocVw.InternetExplorer
    
    ieApp.Visible = True
    
    ieApp.Navigate "www.realtor.com/local"
    
    Do While ieApp.Busy
    Loop
    
    
    Dim ieElement As Object
    
    Set ieElement = ieApp.Document.getElementByID("local-search-input")
    
    ieElement(0).Value = "Biloxi, MS"
    ieElement(1).Click
    End Sub

    I'm encountering the error at the line: ieElement(0).Value = "Biloxi, MS" - any assistance troubleshooting what might be causing the error is appreciated!
    Monday, June 16, 2014 4:40 PM

Answers

  • Would you not be better of navigating to the appropriate page? Probably having a list of all cities in a table with their corresponding code, or construct the string like.

    ieApp.Navigate "http://www.realtor.com/local/" & Replace(Replace(yourVariable, ", ", "_"), " ", "-")

    Where yourVariable could be something like Biloxi, MS the replace will parse it as Biloxi_MS


    Happy to help ! When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answered

    • Marked as answer by Kelci Wednesday, June 25, 2014 7:01 PM
    Wednesday, June 25, 2014 12:04 PM

All replies

  • Would you not be better of navigating to the appropriate page? Probably having a list of all cities in a table with their corresponding code, or construct the string like.

    ieApp.Navigate "http://www.realtor.com/local/" & Replace(Replace(yourVariable, ", ", "_"), " ", "-")

    Where yourVariable could be something like Biloxi, MS the replace will parse it as Biloxi_MS


    Happy to help ! When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answered

    • Marked as answer by Kelci Wednesday, June 25, 2014 7:01 PM
    Wednesday, June 25, 2014 12:04 PM
  • Fantastic workaround!  This worked perfectly for what I'm trying to accomplish - thanks for your help!
    Wednesday, June 25, 2014 7:02 PM