Solved

Need to get a word (what user clicks on) from IE into my VB program

Posted on 2006-10-25
3
190 Views
Last Modified: 2010-04-30
I have been looking some sample code, found this very promising one, it traps mouse up events etc:
http://www.freevbcode.com/ShowCode.Asp?ID=1606

I need to get a word which user clicks in IE window into my program; a double click on word selects text, so it can be also this.
It seems that sendmessage API does not give text here or I did something wrong.

I have been thinking this for a while so it's difficult.

Matti
0
Comment
Question by:Matti
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
Ark earned 500 total points
ID: 17808055
Hi
Assuming you're using my sample from above link:

Add following function to Form code:

Private Function GetWordFromClick(doc) As String
    Dim evt, range
    Set evt = doc.parentWindow.event
    Set range = doc.body.createTextRange
    range.moveToPoint evt.clientX, evt.clientY
    range.Expand "word"
    GetWordFromClick = range.Text
End Function

' Now just call it from mouseover/mousedown/mouseup events:


Private Sub IEWin_IEMouseDown(hwnd As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
   '....
   Debug.Print GetWordFromClick(IEWin.IE(CStr(hwnd)).IEctl.document)
End Sub

'Note - this code works with IE5 and higher
0
 
LVL 27

Expert Comment

by:Ark
ID: 17808118
PS: To get Selection:

Private Function GetSelectedWord(doc) As String
    GetSelectedWord = doc.selection.createRange.Text
End Function
0
 
LVL 14

Author Comment

by:Matti
ID: 17809817
Hi!

Thanks! it's great code!

Matti
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now