How to map a shortcut key to a routine in COM AddIn for Excel 2007
Unfortunately it's not possible to directly assign a shortcut for a routine
in an ActiveX dll, such as a ComAddin.
One way or another will need a bit of help from VBA. As your ComAddin has a
button to call your routine the simplest way would be to trigger its click
event, which I assume you are already trapping with WithEvents in your
ComAddin.
In VBA,
Sub MyCopyAction()
dim cbt as commandbarbutton
set cbt = commandbars.findcontrol(tag:=myTag)
' or maybe say
set cbt = myBar.Controls(myCaption)
' and the fire the button
cbt.Excecute
End Sub
Another way would again from a VBA macro to call a public method in a public
class (with it's instancing set to MultiUse or GlobalMultiUse). You'd
probably also want to set a reference to the dll in the VBA project, though
not necessary if use CreateObject to instanciate the class. You could also
use the Connect class if Public though I'd suggest use an ordinary class.
Regards,
Peter T
"buddylake" wrote in message
...
1. Background:
I have a COM addins developed in Visual basic 6.0 for EXCEL 2007. The COM
addin has its toolbar visible. It exposes customized 'Copy' as a button
on
the toolbar, which will call MyCopyAction routine in the COM addin.
2. What I want:
I want to map a shortcut key for the customized 'copy' operation, which
indeed invoke the same routine as that on toolbar, i.e. MyCopyAction.
3. What I tried in the COM addin:
I added the following line in
Private Sub AddinInstance_OnStartupComplete(custom() As Variant)
...
Application.OnKey "+^c", "MyCopyAction"
...
End Sub
Problem was: Message box from EXCEL "cannot run the macro MyCopyAction
...".
MyCopyAction is not a macro. It's a routine in the COM AddIn. What
options
do I have to make it work?
Thanks!
|