I'm trying to access an Internet Explorer session via Excel VBA. I want to select a bunch of text and links in IE, then use that selection with Excel VBA to populate the sheet.
Namely, I want to obtain the "selected" links. I figured since it's easy to obtain the collection of links in a HTML document, then getting the "selected" links would be easy. Also, I can get the "selection" object of the HTML Document, however it's not returning any text.
However, what I can't seem to figure out is what are the selected hyperlinks. I tried to use this to get the selected text, then filter on link collection, but my Selection Object is showing empty. Maybe you forum members know a way to get the collection of selected hyperlinks.
Namely, I want to obtain the "selected" links. I figured since it's easy to obtain the collection of links in a HTML document, then getting the "selected" links would be easy. Also, I can get the "selection" object of the HTML Document, however it's not returning any text.
However, what I can't seem to figure out is what are the selected hyperlinks. I tried to use this to get the selected text, then filter on link collection, but my Selection Object is showing empty. Maybe you forum members know a way to get the collection of selected hyperlinks.
Code:
Dim IE As InternetExplorer
Set IE = New InternetExplorer
With IE
.Navigate "http://www.randomsite.tv"
Do Until IE.ReadyState = READYSTATE_COMPLETE: Loop
End With
IE.Visible = True
MsgBox "Wait. Select HTML text. Click OK."
Dim IEDOC 'As HTMLDocument
Set IEDOC = IE.Document
Dim IEDocLinks 'As DispHTMLElementCollection
Set IEDocLinks = IEDOC.Links ' '
Dim IESel
Set IESel = IEDOC.Selection
Dim SelText
Set SelText = IESel.createRange '.Text