Hello,
So basically I'm trying to create an add-in. Most of the functionality is in the ribbon but some procedures will just run better as keyboard shortcuts. I don't want the add-in to be a permanent fixture in Excel. In other words, the user will just open the add-in file directly (which causes a menu to be added to the ribbon) then exit the add-in when done. The add-in is closed using a button I put on its ribbon tab since you can't really close them directly. No problems there. All of that works fine.
My problem comes when I try to assign keyboard shortcuts. Here's what I have now:
The "Open" part works just fine. However, when I exit the add-in (using the button in the ribbon), the shortcut assignment does not get removed. If I press CTRL-SHIFT-A after closing, it actually reopens the add-in and executes the procedure. It is especially strange that the "BeforeClose" procedure does definitely run because I see "BF Close" print in the immediate window when I exit.
Even more strange, if I type
into the immediate window, it does manage to unassign the shortcut. So, as you can imagine, I'm pulling my hair out trying to figure out why this isn't working.
I've also tried this in the close event which is supposed to reset the shortcut to it's default but that doesn't work either:
Thank you for your help.
So basically I'm trying to create an add-in. Most of the functionality is in the ribbon but some procedures will just run better as keyboard shortcuts. I don't want the add-in to be a permanent fixture in Excel. In other words, the user will just open the add-in file directly (which causes a menu to be added to the ribbon) then exit the add-in when done. The add-in is closed using a button I put on its ribbon tab since you can't really close them directly. No problems there. All of that works fine.
My problem comes when I try to assign keyboard shortcuts. Here's what I have now:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Debug.Print "BF Close"
Application.OnKey "+^A", ""
End Sub
Private Sub Workbook_Open()
Debug.Print "Open"
Application.OnKey "+^A", "TestSC"
End Sub
The "Open" part works just fine. However, when I exit the add-in (using the button in the ribbon), the shortcut assignment does not get removed. If I press CTRL-SHIFT-A after closing, it actually reopens the add-in and executes the procedure. It is especially strange that the "BeforeClose" procedure does definitely run because I see "BF Close" print in the immediate window when I exit.
Even more strange, if I type
Code:
Application.OnKey "+^A", ""
into the immediate window, it does manage to unassign the shortcut. So, as you can imagine, I'm pulling my hair out trying to figure out why this isn't working.
I've also tried this in the close event which is supposed to reset the shortcut to it's default but that doesn't work either:
Code:
Application.OnKey "+^A"
Thank you for your help.