Home » excel » c# – Excel automation, how to detect if user runs macro in excel worksheet or clicks 'Run Macro' CommandBarControl?

c# – Excel automation, how to detect if user runs macro in excel worksheet or clicks 'Run Macro' CommandBarControl?

Posted by: admin March 9, 2020 Leave a comment

Questions:

Is there some event in the .net automation libraries that can detect when the user who is working on the excel file, has run a macro?

For example, the user opens an excel document which contains an macro, than he runs the macro and the .net application, that is attached to that excel process detect the start macro event?

or maybe bind the macro function to a delegated event in the application..

edit:

Can the ‘Run Macro’ CommandBarControl click event be caught from the code behind?

How to&Answers:

I do not know if there is ‘an event’ in the .NET automation but I know TrackToAct.com (full disclosure my co.) has a VBA code snippet or DLL that your drop into track events. It enables you to tag events and report on the usage via web dashboard.

Answer:

Having never done this myself, I can’t say for sure how you would define that specific application event, but this page here gave me some useful information on defining your own events through class modules. http://www.cpearson.com/excel/Events.aspx

edit: The whole page is on events, to read about defining your own scroll down about 4/5 of the way.