Assign keyboard shortcut to run procedure

前端 未结 9 2042
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 04:35

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.

相关标签:
9条回答
  • 2020-11-29 05:08

    I ran into this problem myself. The only solution I have is to record the macro in an excel workbook first. Then, drag and drop THE MODULE from the open workbook into the add-in modules. This will be a copy of the above module, but the keyboard shortcut you assigned to it will thankfully persist.

    I just record a garbage macro and move it in there, then copy the code from my real module afterwords.

    Felt so great to figure this out, I felt like I had to reply to the 5 year old posts I found on the subject!!!

    0 讨论(0)
  • 2020-11-29 05:11

    Here is how to assign a keyboard shortcut to a custom macro in Word 2013. The scenario is you created a macro named "fred" and you want to execute the macro by typing Ctrl+f.

    1. Click on File, Options.
    2. Click on Customize Ribbon (from my perspective this is the non-intuitive step).
    3. Click "Keyboard shortcuts: Customize" button.
    4. In the Categories listbox scroll down to the buttom and select Macros.
    5. The Macros list box should now show the list of custom macros. Select "fred".
    6. Click the "Press new shortcut key" textbox to make it active.
    7. Type Ctrl+f. This should appear in the textbox.
    8. Look at the "Current keys" listbox. In this case it shows "Currently assigned to NavPaneSearch".
    9. If you don't mind overriding that default, click the "Assign" button on the lower-left to assign "Ctrl+f: to run your "fred" macro.

    By default the assignment is saved in the Normal.dotm document template. If this keyboard assignment is unique to this document then you may wish to change the "Save changes in" dropdown to your document name.

    0 讨论(0)
  • 2020-11-29 05:11

    The problem that I had with the above is that I wanted to associate a short cut key with a macro in an xlam which has no visible interface. I found that the folllowing worked

    To associate a short cut key with a macro

    In Excel (not VBA) on the Developer Tab click Macros - no macros will be shown Type the name of the Sub The Options button should then be enabled Click it Ctrl will be the default Hold down Shift and press the letter you want eg Shift and A will associate Ctrl-Shift-A with the Sub

    0 讨论(0)
提交回复
热议问题