How to click a link inside a table using VBA

swapnilk

Board Regular
Joined
Apr 25, 2016
Messages
78
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi,

I am trying to scrap data from a website. I got to the point where i enter some data and click submit, then a table opens below the submit button, i want to click on the value in the 2nd row 7th column to move further.

VBA Code:
Option Explicit
Const sSiteName = "some_website"

Private Sub CommandButton1_Click()
    Dim oIE As Object
    Dim oHDoc As HTMLDocument
     
    Set oIE = CreateObject("InternetExplorer.Application")
    
    With oIE
     .Visible = True
     .navigate sSiteName
    End With
    
    While oIE.readyState <> 4
        DoEvents
    Wend
 
    Set oHDoc = oIE.document
    
    With oHDoc
        .getElementById("formID").Value = "58"
        .getElementById("bankName").Value = "1273"
        .getElementById("period").Value = "31-MAR-2020"
        .getElementById("toDate").Value = "31-MAR-2020"
        oIE.document.forms(0).submit
        Application.Wait (Now + TimeValue("0:00:05"))
   
    End With
      
End Sub

HTML:
<div id="format">
                    <fieldset class="ff" style="width: 565px">
                        <div class="fm-optional">
                            <table cellspacing="0" cellpadding="4" rules="all" border="1"
                                id="ctl00_ContentPlaceHolder1_GridView1"
                                style="width: 100%; border-collapse: collapse;">
                                <tr
                                    style="color: White; background-color: #403F36; fofont-weight: bold; font-size: 12px">
                                    <th scope="col" width="28%">
                                        Uploaded Return
                                    </th>
                                    <th scope="col" width="16%">
                                        Reporting Date
                                    </th>
                                    <th scope="col" width="16%">
                                        Date Uploaded
                                    </th>
                                    <th scope="col" width="16%">
                                        Reporting Status
                                      </th>
                                     <th scope="col" width="6%">
                                        IsRevised
                                    </th>
                                    <th scope="col" width="16%">
                                        Processing Status
                                    </th>
                                    <th scope="col" width="16%">
                                        Download Files
                                    </th>
                                </tr>
                                    <tr class="subhead" align="center"
                                        style="background-color: #EFF3FB;">
                                        <td class="subhead" align="center" style="width: 5%;">
                                        <a target="_blank"
                                                href="/ABCD/tiles/viewDetailTile.jsp?enc=">
                                                DATA.xml </a>
                                        </td>
                                        <td class="subhead" align="center" style="width: 5%;">
                                            31-MAR-2020
                                        </td>
                                        <td class="subhead" align="center" style="width: 5%;">
                                            12-NOV-2020 15:59:20
                                        </td>
                                        <td class="subhead" align="center" style="width: 5%;">
                                            Final
                                            </td>
                                               <td class="subhead" align="center" style="width: 4%;">
                                            No
                                        </td>
                                        <td class="subhead" align="center" style="width: 5%;">
                                            Completed
                                        </td>
                                        <td class="subhead" align="center" style="width: 5%;">
                                            <a href="/ABCD/DownloadFileServlet?File=FileName.xml&id=2837008&formId=58&fileStatus=Completed">
                                                <span class="glyphicon glyphicon-download" style="cursor: pointer;">download</span>
                                            </a>
                                        </td>
                                    </tr>

After running the above VBA, i want to be able to click on the 'download' in the above HTML code to download the XML file but i can't seem to figure it out. I tried the below code but it gives "Run Time error 91 Object variable or with block variable not set' error.

VBA Code:
oIE.document.getElementsById("ct100_ContentPlaceHolder1_GridView1")(1).getElementsByTagName("tr")(1).getElementsByTagName("td")(5).Click

Can someone please help me with the code?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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