none
Intercepting Click Events on Workbook tabs RRS feed

  • Question

  • With Excel VSTO we are able to add various functionality as part of an addin, such as add an extra option to the context menu when right clicking on a worksheet tab (in the bottom left of excel). Is it possible to extend, override, or otherwise modify the Click events and handlers for the CommandBar that is the worksheet tabs? I'm able to fetch the proper CommandBar, but the documentation notes at it is read only. Is there public API that allows us to intercept clicks on specific work sheet tabs so we can then run non-default functions?
    Thursday, June 13, 2019 4:31 PM

All replies

  • Hello Randy,

    It would be better to post a screenshot where exactly you are clicking in Excel and what actions you'd like to handle.

    As far as I understand you may be interested in handling the following events (depends on your context - just choose the better one):

    Workbook.SheetActivate - is fired when any sheet is activated.

    Workbook.SheetDeactivate - is fired when when any sheet is deactivated.

    Application.WorkbookNewSheet - is fired when a new sheet is created in any open workbook.


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Thursday, June 13, 2019 4:47 PM
  • It seems I'm not allowed to post images until the account is verified, but I am speaking about the Tab bar in the bottom left hand corner of excel, (Default for a new file it would only have "Sheet1" and the Add button)

    I'd like to intercept clicks on a tab in the bar, stop the default switching from happening, and running my own code. I will also be taking a moment to investigate your suggestions, but it sounds like this will fire after the sheet has already switched? Ideally I'd like to be able to catch it before switching, and stop it entirely.

    Thanks.

    Thursday, June 13, 2019 6:05 PM
  • The Excel object model doesn't provide such events. However, you may handle the events described above and then return back. You just need to track where the user navigates from.

    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Thursday, June 13, 2019 6:19 PM