• key binding code (Word 2002 /XP SP3)

    Author
    Topic
    #437077

    Hello

    I am using the below code using Keybinding.

    Im finding that my code is not assigning the shortcut keys confused

    any ideas?
    diana

    ‘shortcut keys to call Save and SaveAs.
    ‘When Word opens, the DM Word template DMIntergration.dot Hummingbird
    ‘code overwrites the shortcut keys assigned to the code in Normal.dot
    ‘This code reassigns the keys back to the code in Normal.dot

    Dim aKey As KeyBinding
    CustomizationContext = NormalTemplate

    ‘from Hummingbird Save & SaveAs remove all the shortcut keys
    For Each aKey In _
    KeysBoundTo(KeyCategory:=wdKeyCategoryMacro, _
    Command:=”Project.Main.HumSave”)
    aKey.Disable
    Next aKey

    For Each aKey In _
    KeysBoundTo(KeyCategory:=wdKeyCategoryMacro, _
    Command:=”Project.Main.HumSaveAs”)
    aKey.Disable
    Next aKey

    ‘reassign the shortcut keys to Corrs code
    CustomizationContext = NormalTemplate
    ‘to File, Save
    KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyS, wdKeyControl), KeyCategory:= _
    wdKeyCategoryMacro, Command:=”CORRSUI.FileSave.Main”
    CustomizationContext = NormalTemplate
    KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF12, wdKeyShift), KeyCategory:= _
    wdKeyCategoryMacro, Command:=”CORRSUI.FileSave.Main”
    CustomizationContext = NormalTemplate
    KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF2, wdKeyShift, wdKeyAlt), _
    KeyCategory:=wdKeyCategoryMacro, Command:=”CORRSUI.FileSave.Main”

    ‘to File, SaveAs
    CustomizationContext = NormalTemplate
    KeyBindings.Add KeyCode:=BuildKeyCode(wdKeyF12), KeyCategory:= _
    wdKeyCategoryMacro, Command:=”CORRSUI.FileSaveAs.Main”

    Viewing 0 reply threads
    Author
    Replies
    • #1038162

      Is it a problem with the code, or with the sequence of execution at load? In other words, if you already have Word fully loaded and settled down ready to work, and then you run your code, does it work then?

      • #1038725

        My code is in a template file called CorrsLib.dot. when Word opens up CorrsLib.dot set the Word environment to our standards.

        When Word opens it loads the global templates…(although Im not sure in which order they get loaded? i thought it was alphabetical)

        Global templates and add-ins:

        CorrsLib.dot
        ….
        DMIntegration.dot.

        Someone recommended to create a new template and name it “ZZZname.dot”, so this is the last template loaded & then run my keybinding code, so its the last thing run on Word open. However I was unsure how to do this?

        I dont think theres an event to do with “Application Open”. And I don’t think an “AutoOpen” module in my “ZZZname.dot” template would work? because the ZZZname.dot is really ‘opened”?

        any ideas?

        diana confused

        • #1038727

          The Document_Open event procedure doesn’t fire in an add-in (global template), but if there is a macro named AutoOpen in a standard module, it will be run when Word statrs (and loads the add-in).

          • #1038767

            >> but if there is a macro named AutoOpen in a standard module, it will be run when Word statrs (and loads the add-in).

            Now I’m confused Hans. I thought you needed a Sub Main in a module called AutoExec to run code when Word starts… confused

            • #1038773

              Sub Main is a relic of very long ago, when each module had to contain a Sub Main, and the module name was used as the name of the macro. All other procedures in the module were merely auxiliary.

              Nowadays (since Office 97 at least, perhaps longer), a module can contain many macros, each with their own name (which should not coincide with the name of a module).

              If you put a macro named AutoExec in a standard module in your Normal.dot, it will be executed when Word starts.
              In global templates = add-ins, a macro AutoOpen will be run when the template is opened, i.e. when Word starts.

            • #1038775

              Thanks for clarification!

    Viewing 0 reply threads
    Reply To: key binding code (Word 2002 /XP SP3)

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

    Your information: