How to assign keyboard shortcut to a vba macro?
Not all Vba code needs a GUI.
Some users love to run them using a shortcut key.
How to create a vba macro keyboard shortcut?
- Press Alt + F8 in Excel.
- Choose macro, then click options
- Enter any valid alphabet after [Ctrl + ] (Example: I)
- Click Ok.
Keyboard shortcut is assigned to a VBA Macro.
Creating a VBA Macro Keyboard Shortcut
To learn about it in detail lets see, how to do this step by step:
Step-1: Insert a Module in VBA project & Copy paste this code.
Sub Macro_Keyboard_Shortcut_Mapping() MsgBox "Did you call me??" End Sub
Step-2: From Excel sheet, press [Alt + F8] or select Menu -> Developer -> Macros
This option will display a popup windows with, list the macro sub procedures in your Excel vba project.
Step-3: Choose the macro that needs a keyboard shortcut & Click “Options” button.
Step-4: Enter any keyboard letter after the text box [Ctrl +] (For example: I) . Also, enter a short description about macro. Description is only a optional feature to let the user know about the functionality.
Step-5: Click ‘Ok’ button.
This completes the creation of a new Keyboard shortcut to a macro.
Caution: Do not use already defined system keyboard shortcuts like [Ctrl + C], [Ctrl+V]. This will make the shortcut to perform inconsistently.
Now, go to the Excel sheet & press [Ctrl + I]. Excel will read the mapping details for this keys combination and invoke the corresponding macro and you can see the message getting displayed as
“Did you call me?”
Hope this information is useful. Enter you comments about this article in below section.