Capture Click and Double Click Events on WebBrowser Control

i2cmevans

New member
Local time
Yesterday, 16:19
Joined
May 23, 2010
Messages
7
I have some WebBrowser controls on a form that basically are just image containers. I want to be able to initiate some events when a user either clicks or double-clicks on the WebBrowser control itself. Is this possible in VBA? I didn't have much luck searching around with Google.

Thanks.
 
The problem is that once your mouse is over the browser the mouse events are handled by the web page, not by Access or VBA.
What would probably work is to handle the DocumentComplete event of the web browser, which provides you with the web page as some kind of HTML DOM object which contains other objects that do source events you can handle in VBA.
Here's some code that might give you some ideas...
Code:
Private WithEvents m_body As MSHTML.HTMLBody
Private WithEvents m_ie As SHDocVw.WebBrowser

Private Sub Form_Open(Cancel As Integer)
   Set m_ie = Me.WebBrowser4.Object
   m_ie.Navigate2 "http://www.microsoft.com"
End Sub

Private Function m_body_onclick() As Boolean
   MsgBox "You clicked the page's body", vbInformation
End Function

Private Sub m_ie_DocumentComplete(ByVal pDisp As Object, URL As Variant)
   Debug.Print URL
   If left(URL, Len("http://www.microsoft.com")) = "http://www.microsoft.com" Then
      Set m_body = pDisp.Document.body
   End If
End Sub
 
Thanks for the recommendations, I'm going to look into that this weekend.
 
I'm looking for similar help... but when I use the sample code, I get "user defined type not defined." Any suggestions?
 
You need to add the relevant references.?

Possibly Microsofr HTML Ojbect Library ?
Maybe also Microsoft WinHTTP services.

They might come up as missing?

HTH
 
Yeah I think it was a reference issue. But it also seems that the mouse events are lost when a PDF is open, since the PDF application takes over.
 

Users who are viewing this thread

Back
Top Bottom