Loading
Excel.Tips.Net ExcelTips (Menu Interface)

List of Macro Shortcuts in All Open Workbooks

If you develop a lot of macros, you may want to list all those macros along with the shortcut keys used to initiate them. Of course, coming up with the code to list the shortcut keys is the tricky part of this problem, as such an ability is not built into Excel directly. (You can do it in Word, but not in Excel. Go figure.)

The easiest way to do this would be to create a macro that exported each of your macros to a .bas text file, then read that text file to determine the shortcut keys. Why this is easiest is because the shortcut keys are not directly available to VBA, but they are written as part of the text file whenever you export macros.

For instance, when you export a macro to a .bas file, it will include lines similar to the following:

Attribute VB_Name = "Module1"
Attribute MyMacro.VB_Description = "My Description"
Attribute MyMacro.VB_ProcData.VB_Invoke_Func = "q\n14"

Your macro could read the .bas file (it is nothing but a text file) and parse what is written there to extract the macro's name and shortcut keys. In the above example, "Module1" is the module the code is in, "MyMacro" is the procedure name, "My Description" is the description for the procedure and "q" is the shortcut key. (The "\n14" seems to be there for all macros; what it signifies is unclear.)

Your code, to be effective, would need to loop through all the modules in a workbook, doing the export and parse steps to get the desired information.

Sound complex? It can be. It's a good thing that there is already a macro available that does all of this. Ivan Moala has written a free Excel add-in that does exactly what is described above. The add-in is available here:

http://www.xcelfiles.com/GetShortCutKeys.html

The code is password protected but Moala has indicated elsewhere on the Internet that the password to access the code is "test." By unlocking the code, you can see exactly how he achieved his results and then create your own macro, or you can just modify his to make sure that whatever is printed matches your needs. For instance, if you want the macro to print the workbook name, module name, macro name, and shortcut key, then you could modify the code to do exactly that.

There is one gottcha that could bite you when using macros of this sort, as well. You need to make sure that you have your macro security set to the proper level to allow the type of access required for the macro to do its work. You do this by choosing, within Excel, Tools | Options | Security | Macro Security. You can then set the security level to the necessary setting: Trust Access VB Projects.

The code described so far allows you to get the desired information for a specific workbook. The next step, of course, is to make sure that the code is applied to each open workbook. This is relatively easy. If your code to process the macros in a single workbook is named something like ListKeys, then you can create a different macro that looks like this:

Sub ListAllKeys()
    Dim wkb As Workbook

    For Each wkb In Workbooks()
        Call ListKeys(wkb)
    Next
End Sub

The macro steps through all the open workbooks, passing each one's name to the ListKeys macro. This name can then be used by your ListKeys procedure to determine where it grabs its information from.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3162) applies to Microsoft Excel 97, 2000, 2002, and 2003.

Related Tips:

Your Data, Your Way! Want the greatest control possible over how your data appears on the page? Excel's custom formats can provide that control, and ExcelTips: Custom Formats can unlock the secrets to creating your own custom formats. Check out ExcelTips: Custom Formats today!

 

Comments for this tip:

Prooffreader    06 Sep 2013, 12:23
There's a cached version of the web page available at: http://web.archive.org/web/20040302213139/http://www.xcelfiles.com/GetShortCutKeys.html
Bryan    13 Aug 2013, 07:33
Unfortunately, as often happens on the internet when relying on someone else to host your content, the link is down.

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 3+4? (To prevent automated submissions and spam.)
 
          Commenting Terms
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2013)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2013)

Our Products

Premium Newsletters

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2014 Sharon Parq Associates, Inc.