Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign keyboard shortcut to run procedure

When I press F5 in the VBA editor I would always like to run my "Sub Skynet()" procedure. Is there any way to assign a keyboard shortcut to this procedure.

like image 412
user1283776 Avatar asked Mar 22 '12 07:03

user1283776


People also ask

What is the shortcut key for run application?

The quickest way to access the Run command window is to use this keyboard shortcut: Windows + R. Simply hold down the Windows key and press R on your keyboard.

How do I assign hotkeys for my keyboard?

Connect the keyboard that you want to configure. Select the Start button, and then select Microsoft Mouse and Keyboard Center. From the displayed list of key names, select the key that you want to reassign. In the command list of the key that you want to reassign, select a command.


2 Answers

According to Microsoft's documentation

  1. On the Tools menu, point to Macro, and then click Macros.

  2. In the Macro name box, enter the name of the macro you want to assign to a keyboard shortcut key.

  3. Click Options.

  4. If you want to run the macro by pressing a keyboard shortcut key, enter a letter in the Shortcut key box. You can use CTRL+ letter (for lowercase letters) or CTRL+SHIFT+ letter (for uppercase letters), where letter is any letter key on the keyboard. The shortcut key cannot use a number or special character, such as @ or #.

    Note: The shortcut key will override any equivalent default Microsoft Excel shortcut keys while the workbook that contains the macro is open.

  5. If you want to include a description of the macro, type it in the Description box.

  6. Click OK.

  7. Click Cancel.

like image 173
Glider Guider Avatar answered Sep 20 '22 18:09

Glider Guider


For assigning a keyboard key to button on the sheet you can use this code, just copy this code to the sheet which contain the button.

Here Return specifies the key and get_detail is the procedure name.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)      Application.OnKey "{RETURN}", "get_detail"  End Sub 

Now within this sheet whenever you press Enter button the assigned macro will be called.

like image 33
user1957196 Avatar answered Sep 22 '22 18:09

user1957196