none
How to assign keyboard shortcut to macro in Word 2010? RRS feed

  • Question

  • I want to assign shortcut keys to my macros in VBA. However, as I create my customize ribbon interface through UI Editor, I cannot find my newly added tab from "customize the ribbon". How can I assign shortcut keys to those macros. In addition, all my macros have an argument since I need to callback through UI Editor. e.g. Sub MyApp(control as IRibboncontrol) Thanks
    Friday, October 11, 2013 3:57 PM

Answers

  • Hi Marcie

    A keyboard shortcut can link only to "Public Sub" macros that have no parameters.

    When I need to do something like you describe - macros linked to keyboard shortcuts AND the Ribbon - I put all of the code that does the work into a separate procedure. I then call that procedure from the "macro stubs" set up for the keyboard shortcuts/Ribbon controls.

    Something like this:

    Sub RunMacro1Keyboard()
      Macro1
    End Sub

    Sub RunMacro1Ribbon(c as IOffice.RibbonControl)
      Macro1
    End Sub

    Private Sub Macro1()
      MsgBox "Macro 1"
      'Lots of other code
    End Sub


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, October 11, 2013 4:08 PM
    Moderator

All replies

  • Hi Marcie

    A keyboard shortcut can link only to "Public Sub" macros that have no parameters.

    When I need to do something like you describe - macros linked to keyboard shortcuts AND the Ribbon - I put all of the code that does the work into a separate procedure. I then call that procedure from the "macro stubs" set up for the keyboard shortcuts/Ribbon controls.

    Something like this:

    Sub RunMacro1Keyboard()
      Macro1
    End Sub

    Sub RunMacro1Ribbon(c as IOffice.RibbonControl)
      Macro1
    End Sub

    Private Sub Macro1()
      MsgBox "Macro 1"
      'Lots of other code
    End Sub


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, October 11, 2013 4:08 PM
    Moderator
  • oh, I see!!!! I will try, thanks soooo much

    Friday, October 11, 2013 4:23 PM
  • Additional note: When I do this, and there are lots of macros involved, I use different modules, one for the Ribbon code, one for the "normal" code, and one for the shared code. Makes it easier to work with, for me :-)

    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, October 12, 2013 10:12 AM
    Moderator