Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VBA for Onclick Events 1

Status
Not open for further replies.

AZGuy82

Technical User
Apr 3, 2011
10
0
0
US
I have been trying to resolve this for quite some time so I thought perhaps somebody on this good board might be able to help.

I am attempting to use VBA to open an IE browser, navigate to a website, and copy everything after clicking through a link.
The VBA code I have does just that, and loads the page properly.

On the source code for the page is the following link:

Code:
<li><a href="#" id="ma99" name="ma99" onclick="gS(1020,16);return false;">Prices</a></li>

I'm still learning and have not found out if there is code that could simulate a click of this link so that the Prices page loads and I can copy it.
I have tried:

Code:
    Dim FindCode
    FindCode = IE.Document.getElementsByID("ma99")
    FindCode.Click

and

Code:
    Dim inputElement
    For Each inputElement In FindCode
    If FindCode.getAttribute("id") = "ma99" Then
    inputElement.Click
    Exit For
    End If

amongst several other options, and am still unable to get this to work. Any chance somebody can help point me in the right direction?


 
That second loop should have been
Code:
    Dim inputElement as IHTMLElement
    For Each inputElement In IE.Document.all
        If inputElement.getAttribute("id") = "ma99" Then
            inputElement.Click
            Exit For
        End If
    Next inputElement

Though I usually stick to the .innerText property (because I hate hunting through html for IDs)

Code:
    Dim inputElement as IHTMLElement
    For Each inputElement In IE.Document.all
        If inputElement.innerHtml = "Prices" Then
            inputElement.Click
            Exit For
        End If
    Next inputElement
 
That works, thank you again Gruuuu you are amazing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top