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!

InternetExplorer Excel VBA - Click Through Selected Text 1

Status
Not open for further replies.

AZGuy82

Technical User
Apr 3, 2011
10
0
0
US
Hi everyone. I would like to ask if it is possible to have Excel VBA simulate a click on a piece of highlighted text.

As an example, I have been able to code the macro so that it pulls the website:

With IE
.Visible = True
.Navigate2 " Do Until .ReadyState = 4: DoEvents: Loop
End With

I have then used onkey to find and select "Contact Us". Is it possible to have VBA click through the Contact Us link and open the next page?

The rest of my VBA code then pulls it into Excel where I can run other macros to find the data I am looking for. I would like to be able to run this for a number of various sites' "Contact Us" link, so that is why I am going through the step of finding it first.
 
I don't see a reference to the current selection of an IE document. Unless that's what activeElement is? You'll need to set an IHTMLDocument object equal to the document of your Browser object, like so:
Code:
Dim IEDoc as IHTMLDocument
[green]'other code[/green]
Set IEDoc = IE.Document
[green]'other code[/green]
IEDoc.activeElement.Click
[green]'other code[/green]
Set IEDoc = Nothing

You may be better off looping through the html elements until you run across the one you want, and use the IHTMLElement.Click method.

maybe this:
Code:
Set IEDoc = IE.Document
For each IEElement in IEDoc.Links
    IF IEElement.innerText = "Contact Us" Then IEElement.click
Next IEElement
 
Gruuuu,

Thank you so much for that, that is perfect ! Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top