Solved

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

Posted on 2006-10-25
3
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month6 days, left to enroll

626 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