Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

.net

excel

vba

vsto

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?

like image 908
zdrsh Avatar asked Sep 13 '12 23:09

zdrsh


People also ask

How do I know if a macro is running?

Right-click the macro in the Navigation Pane, and then click Design View. On the Design tab, in the Tools group, click Single Step. Click Run. If the macro is a new or edited macro, you will be prompted to save the macro before you can run it.

Can macro run automatically when Excel is opened?

Using Auto open method to run a macro automatically: Insert a New Module from Insert Menu. Copy the above code and Paste in the code window. Save the file as macro enabled workbook. Open the workbook to test it, it will Run a Macro Automatically.


2 Answers

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.

like image 37
armadadrive Avatar answered Oct 02 '22 03:10

armadadrive


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.

like image 178
I001962 Avatar answered Oct 02 '22 04:10

I001962