I have the rather small task of creating an Excel Add-In with VSTO in C# (it's a requirement), where I have to provide some information in a TaskPane as soon as a chart has been selected in any Workbook/Worksheet.
As I am totally new to VSTO or Office Extension in general, I don't seem to find any dedicated event or other possibility to recognize the moment the user selects an embedded chart in Excel.
I looked around and tried two things so far, but both don't seem to work as I intented them to:
- Listen to the
Application.SheetSelectionChange
event to intercept the selection of the chart. I soon found out that this event does not fire when a chart has been selected. The documentation states that this does not happen for ChartSheets, so I guess it is true for embedded charts, too. - Traverse all the charts as soon as a worksheet has been activated and attach to a possible Activated event. But to my surprise, there is none (as far as I know).
After looking around the Interop API for a while without success (due to my inexperience with VSTO I may have not been looking in the right places though), I tried a very crude solution just to see if anything works for me.
I created a thread that polls the Application.ActiveChart
property and, as soon as it is not null, I retrieve the information I need and display it in my TaskPane - otherwise I hide it.
This solution, of course, is the one I really don't want to use, especially under the cicrumstance that multithreading under COM can be very unforgiving very quickly.
How could I implement a solution that recognizes a user's selection of a chart in Excel as soon as it occurs? Any pointers or other clarifications about VSTO I might need to know?