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

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Any reason key map gets undone? (Word 2003 SP2)

    Author
    Topic
    #441107

    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 confused

    Viewing 0 reply threads
    Author
    Replies
    • #1058344

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

      • #1058441

        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

        • #1058445

          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.

          • #1058836

            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! rofl Well, at least I have a nice, clean new template.

            Thanks again,
            Kim

            • #1058872

              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

            • #1058981

              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

            • #1059037

              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

            • #1059213

              Very cool Jan,

              Thanks! grin Kim

    Viewing 0 reply threads
    Reply To: Any reason key map gets undone? (Word 2003 SP2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: