Results 1 to 9 of 9
  1. #1
    New Lounger
    Join Date
    Jul 2003
    Location
    Emanuel, South Australia, Israel
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Strange but True (2000/sp3)

    I made a procedure that uses three modules, each with one macro. The first copies the third to the normal template and calls the second. the second does some things and then calls the third in the normal template which attaches the normal template (thereby eliminating the calling macro) and renames the active doc. Here's the catch: When you run the procedure from the Macros dialog (Alt-F8) it works, when you run it from a keyboard shortcut, it works, but when you run it from a Tool Button it refuses to run the Normal template macro. I finally made a fourth short macro the run the first macro and used a tool button to run the fourth, and that works. Strange but true!!

  2. #2
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange but True (2000/sp3)

    I'm not a VBA expert, but try deleting the tool button & recreating it, making sure it's saved in the correct template. Is it possible that either it was saved elsewhere (a global template or a document) or that you made changes in the path name used by the toolbar button after it was created?
    Cheers,

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Strange but True (2000/sp3)

    The OnAction property for a CommandBar control stores more of the "path" to the procedure (e.g., ModuleName+ProcedureName or even ProjectName+ModuleName+ProcedureName). Apparently the Macros dialog and the keyboard shortcuts use the more old-fashioned "near-to-far" method, checking the most local context first and progressing from there until a matching macro is found.
    Attached Images Attached Images

  4. #4
    New Lounger
    Join Date
    Jul 2003
    Location
    Emanuel, South Australia, Israel
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange but True (2000/sp3)

    I did that several times. The really strange part, that I guess was not made clear is that the first and second macros run but the call to the third macro (in the Normal template) does not get run.

  5. #5
    New Lounger
    Join Date
    Jul 2003
    Location
    Emanuel, South Australia, Israel
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange but True (2000/sp3)

    The really strange part, that I guess was not made clear, is that the first and second macros run but the call to the third macro (in the Normal template) does not get run. Figure that out, if you believe it.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Strange but True (2000/sp3)

    What is the code in the second macro that calls the third macro? Are you using Application.Run?

    In which template/document is the less-than-fully-functional toolbar button stored?

  7. #7
    New Lounger
    Join Date
    Jul 2003
    Location
    Emanuel, South Australia, Israel
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange but True (2000/sp3)

    Here is the calling code:

    Normal.ConvertAutotext2.ConvertAutotext2

    Here is the called code that runs or not depending on whether you start with a tool button configured directly to the first macro (as you suggested) or by other means, as described previously.
    Sub ConvertAutotext2()

    'this module is copied to the Normal template and run
    ' from there at the end, since as soon as the attached template is blanked,
    ' all its macros are disabled

    With ActiveDocument
    .UpdateStylesOnOpen = False
    .AttachedTemplate = ""
    L = Len(.name)

    .SaveAs (Left(.name, L - 4) + "-X")
    End With
    End Sub

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Strange but True (2000/sp3)

    > Here is the calling code:
    > Normal.ConvertAutotext2.ConvertAutotext2

    I think this syntax can be flaky. Assuming this is the code in your second macro, try using Application.Run to run ConvertAutotext2.
    <hr>Subject: Re: Calling procedure in another template (XP) [#234629]
    Poster: jscher2000
    Posted on: 13-Mar-03 02:50

    This is a common topic of discussion on the VB/VBA board, so I am cross-referencing posts over there. (E.g., see Post #182610, or this thread or this other one).

    To address your specific questions, the online help for Word 2000 says:
    <UL>--------------------------------------------------------------------------------
    Application.Run MacroName

    MacroName Required String. The name of the macro. Can be any combination of template, module, and macro name. For example, the following statements are all valid.

    Application.Run "Normal.Module1.MAIN"
    Application.Run "MyProject.MyModule.MyProcedure"
    Application.Run "'My Document.doc'!ThisModule.ThisProcedure"
    --------------------------------------------------------------------------------[/list]In my experience with global templates, sometimes the dotted notation is necessary and sometimes it isn't. Perhaps it's the way that the procedure is declared (e.g., Sub vs. Public ?).
    <hr>
    For a limited time only, you can consult this thread for more ideas.

    > Here is the called code that runs or not depending on whether you start with a tool button configured directly to the
    > first macro (as you suggested) or by other means, as described previously.

    Actually, I haven't suggested anything relating to toolbars yet. I don't know enough about how they are created and in what context to make a recommendation on that.

  9. #9
    New Lounger
    Join Date
    Jul 2003
    Location
    Emanuel, South Australia, Israel
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Strange but True (2000/sp3)

    It makes little difference if the original calling code (Normal.ConvertAutotext2.ConvertAutotext2) is used or the Run method. The same weird behavior is observed:
    When the macro containing the call to the normal template macro is run from another macro ("ConvertAutotextStart") that is run from a custom tool button, the normal template code is NOT run.
    When the macro containing the call to the normal template macro is run from another macro ("ConvertAutotextStart") that is run from a keyboard shortcut, the Macro dialog box or a special macro: "Application.Run MacroName:="ConvertAutotextStart" It works fine, even if this last macro IS run from a custom tool button!!??

    If anyone is interested in receiving the template to try it, I will be happy to send it.

Posting Permissions

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