Solved

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

Posted on 2006-10-25
3
220 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 28

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 28

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 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