• Module/Procedure Ambiguity (VBA/Word/2003-2007)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Module/Procedure Ambiguity (VBA/Word/2003-2007)

    Author
    Topic
    #454693

    I have a project which is distributed to a number of users as an add-in. On Launching Word the add-in rebuilds the command bar which is specific to its procedures. Some of my users have outdated versions of the add-in’s modules stored in their Normal.dot templates. I find that the outdated macros are being fired in these cases.

    The OnAction command is:
    cbb.OnAction = “module.procedure”

    The add-in project appears in the Project Explorer as “Macros (_1_Macros)”

    How can I revise the code to force use of the add-in procedure? Surely it’s possible.

    Viewing 1 reply thread
    Author
    Replies
    • #1129407

      It should be automatic that add-ins take precedence over Normal.dot:[indent]


      Conflicting Customizations

      Because you can store customizations in multiple locations and the scope of customizations in one location can overlap the scope of those in another location, conflicts can arise. To resolve such conflicts, Word assigns precedence to customizations according to the following locations:

      1. The active document. Customizations stored in the active document take precedence over any other customizations that are present.
      2. The template attached to the active document. Customizations stored in the template attached to the active document take precedence over customizations stored in add-in files or in the default global template (Normal.dot).
      3. Add-in files, in order of loading. The most recently loaded add-in file takes precedence over add-in files loaded earlier.

        Note: Because you can load add-in files automatically from the Word Startup folder, or from the Microsoft Office Startup folder, and manually from any location at any time, there is no way to determine that your file will load before or after any other particular add-in file.

      4. The default global template (Normal.dot). Customizations stored in the default global template are loaded first, which means that customizations stored in all other locations can overwrite them.

      [/indent]See: Customizing Word 2003 — Conflicting Customizations

    • #1129409

      You could try the different syntax options documented for Application.Run and see whether those help in calling the correct procedure. See Run Method [Word 2007 Developer Reference] @ MSDN and your thread Application.Run (VBA/Excel/2003).

      • #1129428

        Thanks for the response Jefferson.
        I think that we have a small disconnect.
        My customization consists of deleting a specific command bar and rebuilding it. As I understand the situation, this customization is vulnerable to modification by other add-ins which might be loaded subsequent to mine. I do not believe that this is my problem.
        The command button apparently will only accept the OnAction data in the form of “Procedure”, or “Module.Procedure”. There does not appear to be any way to define the file containing the module,
        Please correct me if I am wrong; as it will make the following workaround unnecessary,

        Workaround

        • Create a new module named MacroRedirect
        • Within MacroRedirect create a procedure for each of the macros which is to be fired by the Command bar.
        • Each of these procedures will consist of only one command Call Module.Procedure
        • Revise the OnAction commands in the customization module to OnAction = “MacroRedirect.MyProcedure”
          [/list] This should always call the correct macro as VBA will start looking for the called procedure in the object closest to the calling procedure.
        • #1129437

          Can you not add into the OnAction data a third form of “Project.Module.Procedure” where Project is the name defined in the Properties section of the Template itself?

          I would be interested to see how your code produces the command bars in Word 2007. I have been doing these as an XML file rather than the same method as earlier versions of Word.

          • #1129446

            Thanks for the thought Andrew.

            >> Can you not add into the OnAction data a third form of “Project.Module.Procedure” where Project is the name…

            I have tried all three names –see graphic — in the manner you suggested; each produced the same results “cannot find the macro”.

            Building the command bar in 2007 uses the same code as 2003, There are two anomalies though; a discussion on these and a copy of the command bar build code can be found in the thread which starts here.

    Viewing 1 reply thread
    Reply To: Module/Procedure Ambiguity (VBA/Word/2003-2007)

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

    Your information: