Results 1 to 4 of 4

Thread: I want to make a number into a shortcut that can run a macro

  1. #1

    I want to make a number into a shortcut that can run a macro

    Register for a FREE account, and/
    or Log in to avoid these ads!

    Basically, i want to be able to hit 1 and have a macro run. I found this code, though i dont know how to bind it to a macro.

    So if i make a simple macro like;

    Sub Adding()
    ' Adding Macro

    ActiveCell.FormulaR1C1 = "=RC[-3]+RC[-2]"
    End Sub

    Then make a new module, and put in;

    Sub test()
    MsgBox "Hello"
    End Sub

    Sub Shortcut1()
    Application.OnKey "1", "test"
    End Sub

    How do i bind the macro to this hotkey?

  2. #2
    Magician NoS's Avatar
    Join Date
    Jan 2013
    British Columbia
    Excel Version
    Excel 2010
    The "1" key by itself..... I don't think so, that would make entering numbers into Excel rather limited.

    From the Help files:
    The Key argument can specify any single key combined with ALT, CTRL, or SHIFT, or any combination of these keys.

    Alt + F8 to bring up the macro dialogue
    select the desired macro
    click OPTIONS

  3. #3
    Not if you put it on the number pad. I assume excel can puzzle out that it is a key of its own.

    The macro recorder states you cant use numbers with the generic marco maker, regardless of ALT or the others. I was told i cant use the recorder anyways, i have to write code.

    My task is to make a number do some random function. I appreciate your reply, but it doesnt tell me anything i dont know already.

  4. #4
    I use this so far.

    Sub Workbook_Open()Application.OnKey "{97}", "test"

    Application.OnKey "{98}", "test2"

    Application.OnKey "{99}", "Test3"

    End Sub


    Sub test()
    MsgBox "Well, finally"

    End Sub
    Sub test2()


    End Sub

    Sub test3()
    ' Add Macro

    ActiveCell.FormulaR1C1 = "A1+A2"

    End Sub.

    Only test3 doesnt work. I dont know the syntax to make it use macros.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts