Results 1 to 9 of 9
  1. #1
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Any reason key map gets undone? (Word 2003 SP2)

    This is odd.

    I have mapped Alt-Q in a global template to run a macro that changes straight quotes and apostrophes to curly. However, I've noticed that the template just erases this key mapping - often. It's not that it's being superseded by something else mapped to Alt-Q, it's no longer there. There are several other mapped keys in this template and none of them have ever been erased.

    Does my template simply have a prejudice against Alt-Q (or for straight quotes)?

    Thanks, Kim <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Any reason key map gets undone? (Word 2003 SP2)

    Do you have code in this or other templates that remove keyboars shortcuts (KeyBindings)?

  3. #3
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: Any reason key map gets undone? (Word 2003 SP2)

    Hi Hans,

    No, which is why this is puzzling. Further, yesterday I replaced the shortcut, saved, then ran the VBA Code Cleaner from the MVP site (which also doesn't seem to have any such code), and Alt-Q disappeared. All the other KeyBindings remained. I couldn't find anything anywhere that would cause this.

    I know that corruption in a template will sometimes make it impossible to access, say, styles or autotext. Is it possible corruption would cause one, particular keybinding to evaporate?

    Kim

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Any reason key map gets undone? (Word 2003 SP2)

    Corruption might be a possible cause of the problem.

    You could create a blank new template and copy all code, autotext, styles and toolbars from the problem template into it (using the organizer), as well as all content (of relevant). Redo the keyboard assignments, and see if the new template works better.

  5. #5
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: Any reason key map gets undone? (Word 2003 SP2)

    Hans,

    In creating a new template, I suddenly realized why the mapping of that one macro must be disappearing.

    The macro project is being removed from the template. It isn't there to be mapped to anymore. The other keys are mapped to styles and other things that don't get removed and restored.

    Duh! <img src=/S/rofl.gif border=0 alt=rofl width=15 height=15> Well, at least I have a nice, clean new template.

    Thanks again,
    Kim

  6. #6
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Any reason key map gets undone? (Word 2003 SP2)

    Hi Kim,

    That's exactly the reason why keybindings are removed when you run VBA Code Cleaner: all modules are first removed from the project and then added again. To add the keybindings again, you could run a little macro like this. Needless to say that you have to repeat the last line for every key you want to bind:

    Sub AddKeyBindings()
    CustomizationContext = ActiveDocument.AttachedTemplate 'Or another template
    KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyQ, wdKeyAlt), KeyCategory:=wdKeyCategoryMacro, Command:="MySub"
    End Sub

  7. #7
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: Any reason key map gets undone? (Word 2003 SP2)

    Thanks much, Jan

    I haven't done much with keybindings (programatically speaking), so this is very helpful. I'll set up a macro to restore my keys and run it whenever I need to clean the code, or create a new template from an old one.

    K

  8. #8
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Any reason key map gets undone? (Word 2003 SP2)

    You're welcome Kim.
    This little sub prints all keybindings found in the attached template of a document at the location of the cursor in that document. So you can check if any is present:

    Sub PrintKeyBindings()
    Dim aKey As KeyBinding
    CustomizationContext = ActiveDocument.AttachedTemplate
    For Each aKey In KeyBindings
    Selection.InsertAfter aKey.Command & vbTab & aKey.KeyString & vbCr
    Next aKey
    End Sub

  9. #9
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: Any reason key map gets undone? (Word 2003 SP2)

    Very cool Jan,

    Thanks! <img src=/S/grin.gif border=0 alt=grin width=15 height=15> Kim

Posting Permissions

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