Capturing shape events and ActiveX events

9 views
Skip to first unread message

Stu McKenzie

unread,
9:11 AM (11 hours ago) 9:11 AM
to Excel-DNA
Hello,
Does anyone know if you can capture Shape events - either just shape Click, or using the shape's Hyperlink?

Alternatively, what's the best way to capture ActiveX command events? 
Is it possible to register to a global ActiveX control event, like button Click? Or do I need to iterate each worksheet and enumerate all the activeX controls
Thanks
Stu

Stu McKenzie

unread,
6:40 PM (1 hour ago) 6:40 PM
to Excel-DNA
I figured out the ActiveX handlers

app.WorkbookOpen += _app_WorkbookOpen;
...
foreach (MsExcel.Worksheet ws in wb.Worksheets)
    foreach (MsExcel.OLEObject obj in (MsExcel.OLEObjects)ws.OLEObjects())
        if (obj.Object is MSForms.CommandButton button)
        {
              MSForms.CommandButtonEvents_ClickEventHandler handler = () =>
              {
                  var command = button.Name;
                  // do something with command
              }
          
              handlers!.Add((button, handler));
              button.Click += handler;
          }

but I had to keep a handle on all the Button objects or they would be disposed after the first button was clicked


still - anyone know if shape events are possible though?
Reply all
Reply to author
Forward
0 new messages