VBscript to click a link

I am in a bit of a quandry.
I am familiar with different types of VBscript that can execute links like document.links(n).click etc.
What I am looking for is a chunk of vbscript that can capture or execute links by their visible text (inner.text?)
so that the VBscript executes a "Go" or "View Details" link, no matter what the href behind it is or what the order is (as the pages are built dynamically).

HELP?

Thanks.
tbrackettAsked:
Who is Participating?
 
Erick37Connect With a Mentor Commented:
MsgBox ie.Document.links(N).innerText

=or=

Dim strText

strText = ie.Document.links(N).innerText
0
 
Erick37Commented:
Using VB6 to open IE and clicking an <A> tag knowing the inner text:

To do this you need to add references to
"Microsoft Internet Controls"
"Microsoft HTML Object Library"

Then, as in this example, search for the right <A> tag to click:

Dim ie As InternetExplorer
Dim oHTML As HTMLDocument
Dim oElement As IHTMLElement

Set ie = New InternetExplorer

ie.Visible = True
ie.Navigate "http://www.techsense.com/html/frames/scripts2.html"

Do While ie.ReadyState <> READYSTATE_COMPLETE
    DoEvents
Loop

Set oHTML = ie.Document

'loop through the <a> tags for a specific one
For Each oElement In oHTML.getElementsByTagName("a")
   
    If oElement.innerText = "Example 1" Then '<< change the text to suit your needs
        oElement.Click 'click it!
        Exit For
    End If
   
Next
0
 
Erick37Commented:
This is better:

For i = 0 To ie.Document.links.Length - 1
   
    If ie.Document.links(i).innerText = "Example 1" Then
        ie.Document.links(i).Click
    End If

Next
0
 
tbrackettAuthor Commented:
Great answers thank you!
Erick37 is definitely the simpler solution, but my followup to this is what would be the command for capturing that innerText?
Better stated, what would "get"

ie.Document.links(N).innerText
0
All Courses

From novice to tech pro — start learning today.