Consulting

Results 1 to 10 of 10

Thread: Solved: Assign shortcut key to style within macro?

  1. #1
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location

    Solved: Assign shortcut key to style within macro?

    I have a macro that creates a couple styles. Is it possible to assign a shortcut key to the styles from within the macro?

    I tried, but I don't see where I can designate the style that I want to give the shortcut to.

    Any help is greatly appreciated!

    Cheryl

  2. #2
    hi Cheryl,

    The follow bit of code assigns the shortcut key "Alt+Shift+Crtl+z" to the Heading 1 style. It is defined in the Normal.dot file.

    [VBA] CustomizationContext = NormalTemplate
    KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyZ, _
    wdKeyControl, wdKeyShift, wdKeyAlt), KeyCategory:=wdKeyCategoryStyle, _
    Command:="Heading 1" [/VBA]

    You should be able to assign your desired shortcut key to the new heading you have created. I would put a bit of error handling in so that the code doesn't fall over if your style, for whatever reason, doesn't get created.

    Be careful you don't overwrite commonly used existing shortcut keys though!

    Cheers,
    Andrew

  3. #3
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Ah. But you don't NEED a macro to assign a style to a shortcut key, unless you want that style and its shortcut key to travel with the document. Let me know...
    ~Anne Troy

  4. #4
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Anne,

    can we create shortcuts for styles without using a macro? This interests me a lot, so can you tell me how?

    I know I can press Ctrl + Shift + U and go to the styles, but how can I set a style by shortcut keys? Lets say a Heading 1?
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  5. #5
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Tools-Customize.

    Choose Styles (all the way down on the left) and then hit the KEYBOARD button.

    Click in Press a keystroke box.

    Type the keystroke and hit Assign.

    I like to use Alt+1 for heading 1, Alt+2 for heading 2, Alt+T for body text, Alt+G for graphic, Alt+B for bullet...etc.
    ~Anne Troy

  6. #6
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Gee Anne,

    I dont have that. I have clicked on Tools - Customize - Commands - Styles - Keyboard, but I dont have the headings styles there, only the normal.

    What else should I do? I use Word 2003 with full installation and I do have the other styles on the document.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  7. #7
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Wow. Never noticed that before. Better have a doc open that (at least) HAS used those styles once.

    I just changed the same line of text to heading1, then 2, then 3. All then appear in that menu...
    ~Anne Troy

  8. #8
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Anne,

    great, exactly. I created text using them and after that they showed there. Now I have attributed the shortcuts to them (copied yours ).

    Thanks.
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

  9. #9
    VBAX Mentor clhare's Avatar
    Joined
    Mar 2005
    Posts
    470
    Location
    Thanks Andrew! That's just what I needed.


    Cheryl

  10. #10
    Administrator
    VP-Knowledge Base VBAX Master
    Joined
    Jan 2005
    Location
    Porto Alegre - RS - Brasil
    Posts
    1,219
    Location
    Hi Cheryl,

    if its solved please mark it solved by clicking on "Thread Tools" and selecting "Mark it solved"
    Best Regards,

    Carlos Paleo.

    To every problem there is a solution, even if I dont know it, so this posting is provided "AS IS" with no warranties.

    If Debugging is harder than writing a program and your code is as good as you can possibly make
    it, then by definition you're not smart enough to debug it.




    http://www.mugrs.org

Posting Permissions

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