Webbrowser ActiveElement question (1 Viewer)

Sleekmac

Registered User.
Local time
Today, 06:19
Joined
Sep 25, 2006
Messages
34
Hi again all! I have a form in Access with an ActiveX WebBrowser control in it. What I want is for the user to select some text within the browser, and for that text to be captured in a string variable. I've been scouring the web all day for a clue as to how to do this, and this is all I could find:

Code:
Private Sub test_Click()
Dim myText As String
Me.mainBrowser.SetFocus
myText = Me.mainBrowser.Document.activeelement.innertext
Debug.Print myText

End Sub

The problem is, myText is all the text on the entire page. It seems that the ActiveElement is the entire page, even when text in the browser is selected. Does anyone know how I can isolate just the selected text please?
 

Sleekmac

Registered User.
Local time
Today, 06:19
Joined
Sep 25, 2006
Messages
34
In case my description was unclear, this is what I am doing:

For example on the google search results page, I am told there are no frames.

Visual Basic(Microsoft) WebClasses - HTML DOM and Objects Library... Document.frames.inputscreen.Document.Forms.datacollectionform.selectboxname The problem arises that in similar websites, the name of the particular form ...
www.tek-tips.com/viewthread.cfm?qid=1204493&page=1 - 27k - Cached - Similar pages

If i select the word "arises" in the text of this one result blurb, I would expect me.mainbrowser.document.activeelement.innertext to return "arises". Instead I get the entire blurb. Interestingly, I do not get all the blurbs. I am going crazy searching the web for info about activeelement and how to specify the scope, getting nowhere. Please please please can someone tell me what I am doing wrong? :D
 

Sleekmac

Registered User.
Local time
Today, 06:19
Joined
Sep 25, 2006
Messages
34
Answer

I finally got it!

Code:
Dim mySel As Object
Dim myText As String
Set mySel = Me.mainBrowser.Document.selection.createRange
myText = mySel.Text

If myText <> "" Then
    Me.mainBrowser.Navigate "http://dictionary.reference.com/browse/" & myText
    Me.mainBrowser.Visible = True
Else
    MsgBox "Error: No text selected"
End If

This returns a string equal to the selected text. Good to know! Makes for a spiffy custom browser, where if I am searching, say, wikipedia, and I come across a term that needs clarification, I just select the text and hit a button on the side of the browser to initiate a new search for that term in the active browser. Much less cumbersome then ^c, back, scroll down and select inputbox, ^v.:cool:
 

Users who are viewing this thread

Top Bottom