How to trap a LEFT click mouse event in Excel VBA?

  • Usage: I want to add a list of Companies to an Excel spreadsheet. The Companies are obtained from I want to trap LEFT Click (so that when I LEFT Click on a Company, it will be added to my Excel Spreadsheet)

    Note: I've already posted the same question on stackoverflow. Here's the link:

  • Update: Read an interesting article on how to trap events, the summary of which is mentioned below (along with the link) . Will give this a try and see if it works!

    Applications based on Visual Basic can contain WebBrowser objects, which can contain other objects—such as HTML document objects. WebBrowser objects, however, do not provide a way to trap all of the events that can occur in the objects they can contain. The WebBrowsercontrol, for example, does not provide a way to trap the onclick event of a button element in an HTML document object the control contains.

    Events in HTML document objects are forwarded up the document object's hierarchy until the top of the hierarchy is reached (or until event forwarding is canceled). This forwarding is referred to in Understanding the Event Model as bubbling. But events do not bubble to the documentobject's container. The top of an HTML document object's hierarchy is the document object. The WebBrowser control does not provide a way to trap the onclick event of a button element because the event does not bubble to the WebBrowser control.

    "Event sinks can be used in Visual Basic-based applications to create customized ways of responding to events that are triggered by Microsoft ActiveX objects such as WebBrowser objects. This approach often uses WithEvents variables to handle events triggered by the ActiveX objects. But if the events don't bubble to the host applications, you can't trap the events. If you can't trap the events, you can't write procedures to handle them."

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!