ReadyState Error wth VBA That Places Text In SearchBox of Website - Stopped Working Recently

jaywenp

New Member
Joined
Mar 12, 2014
Messages
42
The purpose of this code is to do a simple search for a using the website's own search box. This code was placing code into the search box and clicking the website's search button. However, I am not sure what has recently changed to prevent the code from executing. The html website element ID tags have not appeared to have changed yet the Readystate error continues to be where the code is failing. I am using IE 11 on my computer. Here is the code that was working with previous IE versions:

Code:
 Dim objIE As SHDocVw.InternetExplorer 'microsoft internet controls (shdocvw.dll)
    Dim htmlDoc As MSHTML.HTMLDocument 'Microsoft HTML Object Library
    Dim htmlInput As MSHTML.HTMLInputElement
    Dim htmlColl As MSHTML.IHTMLElementCollection
     
    Set objIE = New SHDocVw.InternetExplorer
     
    With objIE
        .navigate "http://XYZ" ' Main page
        .Visible = 1
        Do While .Busy: DoEvents:   Loop
            Do While .readyState <> 4: DoEvents: Loop
            Set htmlDoc = .document
                Set htmlColl = htmlDoc.getElementsByTagName("INPUT")
                For Each htmlInput In htmlColl
                    If htmlInput.Name = "search" Then
                        htmlInput.Value = Replace(Range("A1").Value, " ", "_")
                                                      
                        End If
                    
                Next htmlInput
                 
                Set htmlDoc = .document
                Set htmlColl = htmlDoc.getElementsByTagName("input")
                Do While htmlDoc.readyState <> "complete": DoEvents: Loop
                    For Each htmlInput In htmlColl
                        If htmlInput.Name = "go" Then
                                htmlInput.Click
            End If
             Next htmlInput
           End With


I have attempted the following with no success of correcting my current problem:

1) I attempted to replace SHDocVw.InternetExplorer with InternetExplorerMedium

2) I have tried both Security settings of: Enabled Protective Mode and Disabled Protective Mode



PLEASE let me know what I am not doing correctly. Any suggestions would be extremely appreciated.

Thank You.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Here is the full code, to include the website:

Code:
Dim objIE As SHDocVw.InternetExplorer 'microsoft internet controls (shdocvw.dll)
    Dim htmlDoc As MSHTML.HTMLDocument 'Microsoft HTML Object Library
    Dim htmlInput As MSHTML.HTMLInputElement
    Dim htmlColl As MSHTML.IHTMLElementCollection
     
    Set objIE = New SHDocVw.InternetExplorer
     
    With objIE
        .navigate "http://en.wikipedia.org/wiki/Main_Page" ' Main page
        .Visible = 1
        Do While .Busy: DoEvents:   Loop
            Do While .readyState <> 4: DoEvents: Loop
            Set htmlDoc = .document
                Set htmlColl = htmlDoc.getElementsByTagName("INPUT")
                For Each htmlInput In htmlColl
                    If htmlInput.Name = "search" Then
                        htmlInput.Value = Replace(Range("A1").Value, " ", "_")
                                                      
                        End If
                    
                Next htmlInput
                 
                Set htmlDoc = .document
                Set htmlColl = htmlDoc.getElementsByTagName("input")
                Do While htmlDoc.readyState <> "complete": DoEvents: Loop
                    For Each htmlInput In htmlColl
                        If htmlInput.Name = "go" Then
                                htmlInput.Click
            End If
             Next htmlInput
           End With

PLEASE see if you can figure a way out to get the code to place text in the website's searchbox. Thank you.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,225,169
Messages
6,183,318
Members
453,155
Latest member
joncaxddd

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top