Home » excel » Excel VBA: can I set up a global right click event?

Excel VBA: can I set up a global right click event?

Posted by: admin May 14, 2020 Leave a comment

Questions:

Is there a way to create an event so that a certain .xlam of mine gets control whenever the user right-clicks ? In this case the user may have several .xlsx (non-macro) workbooks open which must remain free of any macro code. If the user right-clicks while one of these macro-free worksheets is open, I’d like the .xlam to gain control and possibly do something.

How to&Answers:

Use a with events variable in a class such as

Private WithEvents mxlApp As Excel.Application

Then use the event SheetBeforeRightClick.

Private Sub mxlApp_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Range, Cancel As Boolean)

End Sub

The xlsx files should have the .xlam file installed in order for it to work. Hope this helps.

http://www.cpearson.com/Excel/Events.aspx

http://www.cpearson.com/Excel/AppEvent.aspx