Extract HREF attrib in HTML for output to Excel

dman78

New Member
Joined
Oct 22, 2016
Messages
14
Office Version
  1. 2016
Platform
  1. Windows
Hello, all,

I am trying to extract the HREF value, but I have <a> without a name and I'm stumped. What am I missing that would allow me to obtain the HREF (javascript:gvClosuresSelectRow('802c3a43-f761-4618-94c7-ade013516718') as per below.

My code is as follows:

VBA Code:
 Dim htmlElement As MSHTML.IHTMLElement

    For Each htmlElement In IE.document.getElementsByTagName("A")
        Debug.Print htmlElement.getAttribute("href")
        htmlElement.Click
    Next htmlElement

This just lists all Elements with tag, but I need to target only this particular href

VBA Code:
<tbody>

    <tr class="GridRow GridViewRow">
        <td style="width:auto;"><a href="javascript:gvClosuresSelectRow('802c3a43-f761-4618-94c7-ade013516718');" title="Screening Incomplete Nov 25, 2021">Select</a></td>
        <td style="width:auto;">Screening Incomplete</td>
        <td style="width:auto;">Nov 25, 2021</td>
        </tr>

    <tr class="GridRow GridViewAltRow">
        <td style="width:auto;"><a href="javascript:gvClosuresSelectRow('7c4b2673-f65b-4ae5-9031-8dd9621903ca');" title="System Closure Nov 28, 2021">Select</a></td>
        <td style="width:auto;">System Closure</td>
        <td style="width:auto;">Nov 28, 2021</td>
      </tr>
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You could get the table element, then its first row and column. This code assumes the table is the first table on the page:
VBA Code:
    Dim table As HTMLTable
    Set table = IE.document.getElementsByTagName("TABLE")(0)
    Debug.Print table.Rows(0).Cells(0).Children(0).href
 
Upvote 0
You could get the table element, then its first row and column. This code assumes the table is the first table on the page:
VBA Code:
    Dim table As HTMLTable
    Set table = IE.document.getElementsByTagName("TABLE")(0)
    Debug.Print table.Rows(0).Cells(0).Children(0).href
Hi John,

Thanks for your reply.

I am getting an "Object doesn't support this property or method" with the Debug.Print Line.

There is only one table on this page so I am not sure why it is having that error.
 
Upvote 0
Maybe:
VBA Code:
    Debug.Print table.Rows(0).Cells(0).getElementsByTagName("A")(0).href
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,577
Members
449,039
Latest member
Arbind kumar

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