I'm looking for a way to catch all keyboard events. I need to test the state of a Ribbon button whenever a key is pressed so that I can run other code based on the state of that Ribbon button. The key or combination that is pressed is not important, just the state of the Ribbon button when any key has been pressed.
I have a Custom Ribbon that has a button which uses the PasteValues IDMSO and so it's enabled state is controlled by Excel. I have another button that should only ever be enabled when this PasteValues button is enabled. I have code that controls the button sufficiently when Paste Values becomes enabled or disabled through Excel's UI but this does not work when it is enabled or disabled through keyboard shortcuts.
Whenever a key is pressed, I want to test the state of the Paste Values button and enable or disable my other button accordingly. It is not important that key strokes be monitored when Excel is in 'cell edit' mode or a userform is running etc.
I could go a different route here and use application.onkeys to remap what specific key combinations like "shift+insert" or "ctrl+v" do but there's always the chance that something gets missed. For instance, when the Paste Values button is enabled, just editing a cell is enough to disable it as editing the cell changes the CutCopyMode property on entry. Since any key on the keyboard (effectively) can put Excel into 'cell edit' mode I think I really need to be monitoring the state of the Ribbon Button when any key was pressed.
Bookmarks