Yahoo Search Button Click/Submit

jaywenp

New Member
Joined
Mar 12, 2014
Messages
42
The following code works well to click a search button, so long as the element has an assigned tag name. Unfortunately I am not able to locate a name element for the Search button on the Yahoo home page. Can someone PLEASE advise on how to successfully re-write the code shown below to click the Yahoo home page Search button. Thank You.

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 "https://Yahoo.com" ' 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(Userform.Textbox.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

Yahoo Search Button
HTML:
<button tabindex="3" title="Search Web" class="rapid-noclick-resp C(#fff) Fz(16px) Px(26px) Py(0) Whs(nw) Bdw(0) Lh(1) enableHover_Bgc($searchBtnHov):h  W(80px) Bdrststart(0) Bdrsbstart(0) Bxsh(n) H(46px) Miw(90px) Bgc(#0f69ff) Bgc(#145aff):h Bgc(#145aff):f glow_Bgc($searchBtnGlow) Bdrs(2px) Bxsh(n)! ua-ie7_H(42px) ua-ie7_Lh(42px) ua-ie8_Lh(42px) ua-ie8_Miw(a)" id="uh-search-button" aria-label="Search Web" type="submit" data-ylk="rspns:nav;t1:a1;t2:srch;sec:srch;slk:srchweb;elm:btn;elmt:srch;tar:search.yahoo.com;tar_uri:/search;itc:0;" data-rapid_p="33"><i class="Fz(26px) Mstart(2px) Icon-Fp2 IconNavSearch Icon-Fp2"></i>
                        </button>
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
The Userform values are successfully placed into the Yahoo Search Box with the above code. However, the Yahoo search engine does not actually move forward. What I would like help with is the code to successfully click/submit the search query for the information in the Search Box coding the Search Button click/submit.

Thank You.
 
Upvote 0
I can't really help with EXACTLY what you are asking for, what I am suggesting however is looping through the values and going directly to the search results with the search terms in the Yahoo box already. This code sample just uses values from an array, but you should be able to adapt it to your exact needs. If this doesn't help you, maybe someone else can.

Code:
Sub test()
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
     Dim strSearchTerms, t
    strSearchTerms = Array("Unicorn Frappucino", "Butterflies")
    With objIE


For Each t In strSearchTerms
    MsgBox "Press OK for next search"
    .navigate "https://search.yahoo.com/search?p=" & Replace(t, " ", "+")
    .Visible = 1
Next


           End With
End Sub
 
Last edited:
Upvote 0
Thank you for your time regarding my question. I did try the code above but I was unable to get Yahoo to automatically search for the different array variables.

Though my code may be considered the long way, I got Yahoo to search for the Userform Textbox variable data by reconnecting the cursor focus on the Search Box and applying the SendKeys code for the Enter Button. If there is an easier solution I would love to get an Excel Guru to explain it on this Thread.

Meanwhile, I hope that the following code may be useful for anyone that cares to use it for a similar objective.

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 "https://yahoo.com"      ' 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 = "p" Then
                        htmlInput.Value = Replace(UserForm.Textbox.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 Trim(htmlInput.Title) = "Search" Then
                            htmlInput.Click      'Activates cursor in Search Box so the following SendKeys command code for pressing the Enter key works
                            Exit For
                        End If
                    Next htmlInput
                End With
SendKeys "+{Enter}"      'This was used to execute the Search as I was unable to create the necessary vba code that would successfully click/submit the Yahoo homepage Search button.
End If

All previous and future input is appreciated.

;)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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