How to find macros for a given shortcut combination

M

Mike C

I have most of my shortcut keys assigned to existing macros. Is there
an easy way to identify which macro a given shortcut (e.g., Ctrl +
Shift + E) is assigned to? Or do i simply have to look at the code for
every single macro to determine which macro that shortcut was assigned
to?

Thanks.
 
D

Dave Peterson

I think it depends on a couple of things.

First, how you assigned the shortcut to the macro and second, what your
definition of "easy" is.

If you recorded a macro and chose to assign the shortcut when you were starting
the recording, then you could look at each of your macros.

There would have been a comment near the top of the procedure that excel created
for you:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 06/30/2010 by Dave Peterson
'
' Keyboard Shortcut: Ctrl+a

=========
If you added the shortcut via the Tools|macro|macros|options button (xl2003
menus), then this comment wasn't created for you.

But you could go into the VBE and use File|Export to export each of the modules
you think may have the macro you're looking for (Could be all modules in all
open workbooks/addins????).

Then open that .bas file in your favorite text editor (like NotePad). You'll
see a comment line like:

Attribute Macro1.VB_ProcData.VB_Invoke_Func = "a\n14"

That "a" before the "\n14" is the shortcut key (ctrl-a in my case).

This technique will also work for the first method of assigning the shortcut key
(while recording the macro).

In fact, if you used code to assign the shortcut key:
Application.MacroOptions "test3", hasshortcutkey:=True, ShortcutKey:="z"

It'll work for that, too.

============

If you have lots and lots of modules in your workbook, then you may want to look
at Rob Bovey's code cleaner program.
You can find it here:
http://www.appspro.com/
or directly
http://www.appspro.com/Utilities/CodeCleaner.htm

It actually exports and re-imports the modules to clean the code of some
detritus. And there's an option to keep the exported text files (*.bas) instead
of deleting when the program finishes.
 

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