Conditional application.onkey in realtime?

A

Andy

Is there a way to use application.onkey to assign the same key to one
macro in workbookA and another Macro in workbookB? And have that same
shortcut key do nothing in WorkbookC? All three workbooks are open at
the same time so I want the appropriate macro to run in the active
workbook.

I tried a few ways making the application.onkey statement conditional
on the activeworkbook, but when the key was assigned, that was that.

TIA,

Andy
 
T

Tom Ogilvy

Use one macro assigned to the key combination.

have it check which workbook is active and take the appropriate action.

the alternative is to use the window activate event to reassign the onkey.
 
A

Andy

Use one macro assigned to the key combination.
have it check which workbook is active and take the appropriate action.

I should have been able to figure this out for myself! I'm sure I can get
this to work if I only have one workbook where I want the key combination to
work and don't want it to work anywhere else. This is the situation I'm
dealing with now, so this will solve my problem.

Not sure if I can make it work if I want the same key combo to work in two
workbooks and do different things in each, with each workbook having no idea
if a conflicting workbook is open, or what the name of that workbook is.
Each would have a workbook_open macro to assign the key and whichever one
opened last would override the other.
The alternative is to use the window activate event to reassign the onkey.

I fooled with this a little, but I couldn't make it unassign when I moved to
another window. In most windows I want the key to be inert, and I never know
what other windows will be open.

I'll fool with these options and post back with better questions.

Thanks,

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top