I have VBA already to fill in search form and click submit. Now i need vba to click on a particular hyperlink out of many

Pr0x1mo

New Member
Joined
May 14, 2015
Messages
20
So i have the code that takes a numerical value out of A1 cell from my work sheet. The macro goes to the website, fills in the search form and clicks submit. This works fine, but when you click submit a list of hyperlinks come up and i need a particular one named "OH - House Bill of Lading"

So how would i add that part to the code i already have?

Rich (BB code):
Public Sub IE_Search_and_Extract()
     
    Dim URL As String
    Dim IE As SHDocVw.InternetExplorer
    Dim htmlInput As MSHTML.HTMLInputElement
    Dim htmlColl As MSHTML.IHTMLElementCollection
    Dim HTMLdoc As HTMLDocument
    Dim Html As HTMLDocument
    Dim Alllinks As Object
    Dim HyperLink As Object
    Dim objIE As SHDocVw.InternetExplorer
    
    URL = "http://eglsiis12c.egl.corp/docvisionsearch/DocVisionSearch.aspx"
     
    Set IE = Get_IE_Window(URL)
    If IE Is Nothing Then
        Set IE = New SHDocVw.InternetExplorer
    End If
     
    With IE
        SetForegroundWindow .hwnd
        .Navigate URL
        .Visible = True
        While .Busy Or .ReadyState <> READYSTATE_COMPLETE
            DoEvents
        Wend
                          
         
        .Document.getElementById("House1_txtHouseBillNum").Value = ActiveSheet.Cells(1, 1)
        .Document.getElementById("House1:btnHouseSearch").Click
        
        While .Busy Or .ReadyState <> READYSTATE_COMPLETE
            DoEvents
        Wend
End With
End Sub

the particular hyperlink i'm trying to click looks like this:



I tried doing this but it gives me an Run-Time error 91 object variable or With Block Variable not set

Rich (BB code):
Public Sub IE_Search_and_Extract()
     
    Dim URL As String
    Dim IE As SHDocVw.InternetExplorer
    Dim htmlInput As MSHTML.HTMLInputElement
    Dim htmlColl As MSHTML.IHTMLElementCollection
    Dim HTMLdoc As HTMLDocument
    Dim Html As HTMLDocument
    Dim Alllinks As Object
    Dim HyperLink As Object
    Dim objIE As SHDocVw.InternetExplorer
    
    URL = "http://eglsiis12c.egl.corp/docvisionsearch/DocVisionSearch.aspx"
     
    Set IE = Get_IE_Window(URL)
    If IE Is Nothing Then
        Set IE = New SHDocVw.InternetExplorer
    End If
     
    With IE
        SetForegroundWindow .hwnd
        .Navigate URL
        .Visible = True
        While .Busy Or .ReadyState <> READYSTATE_COMPLETE
            DoEvents
        Wend
                          
         
        .Document.getElementById("House1_txtHouseBillNum").Value = ActiveSheet.Cells(1, 1)
        .Document.getElementById("House1:btnHouseSearch").Click
        
        While .Busy Or .ReadyState <> READYSTATE_COMPLETE
            DoEvents
        Wend
    
   
    
        .Document.getElementById ("SearchResults_dgResults__ctl5_lnkbtnGetImage")
        .Document.getElementById("OH - House Bill of Lading").Click
        


        
        










End With
End Sub
 

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.

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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