Results 1 to 7 of 7
  1. #1
    New Lounger
    Join Date
    Feb 2001
    Location
    Jackson, Mississippi, USA
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Application.Run macro in another template (Word 2000)

    I have two templates loaded. I have an error routine in template #1 (LssMenu). Later I load template #2 (LSS_Summary) and want to be able to use the error routine in template #1 to handle errors. The error routine (ErrorHandler) is in its own standard module (GetAbend). I'm trying something like this:

    On Error GoTo Abend:

    code where error may or may not happen

    Abend:
    Application.Run MacroName:="LssMenu.GetAbend.ErrorHandler", _
    varg1:="LSS_Summary.M_Summary", varg2:="InitVars"

    The error message is 'Object doesn't support this property or method.'

    If I copy the GetAbend error module to the Normal template, everything works fine.

    I saw something on the web about adding a reference, but nothing concrete.

    BTW, what happened to the search, or I would try to find the answer first without bothering ya'll.

    Thanks,
    Ann Brandon

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.Run macro in another template (Word 2000)

    You need a reference to the LssMenu project.
    ErrorHandler must be Public, not Private.

    What is LSS_Summary?
    What is M_Summary?

  3. #3
    New Lounger
    Join Date
    Feb 2001
    Location
    Jackson, Mississippi, USA
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.Run macro in another template (Word 2000)

    LSS_Menu is name of first template loaded
    LSS_Summary is the name of the second template added using AddIns.Add
    M_Summary is the name of a module in LSS_Summary holding code shared by various forms

    I tried pasting in this code into LSS_Summary before raising the error and got error
    "Name conflicts with existing module project or object library."

    Sub AddReference()
    On Error GoTo ErrorHandler
    ThisDocument.VBProject.References.AddFromFile "LssMenu.dot"
    Exit Sub
    ErrorHandler:
    Select Case Err.Number
    Case Else
    MsgBox Err.Description & "; " & Err.Number & _
    "; " & Err.Source
    Err.Clear
    End Select
    End Sub

    Am I on the right track?

    Thanks, Ann

  4. #4
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Application.Run macro in another template (Word 2000)

    If LssMenu is an OPEN project, then GetAbend is interpreted as a module within the LssMenu project, and ErrorHandler should be Public, not Private.

    If LSS_Summary is an Open Project, then M_Summary would be interpreted as a module name, so it would seem that varg1 would be passing invalid parameter to ErrorHandler.

    varg1 and varg2 must pass parameters that match the expected arg types in ErrorHandler.

  5. #5
    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: Application.Run macro in another template (Word 2000)

    Your code should work if LssMenu is the name of the project as well as the name of the template. If not, you might be able to use the ! (bang) notation illustrated in the online help for Application.Run.

  6. #6
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Application.Run macro in another template (Word 2000)

    Ann,

    Have to admit to being lazy and not sussing out every bit of code, but want to make a couple of suggestions that may be helpful:

    You don't mention whether LssMenu is a global temple but I'm assuming it is. If LssMenu is a global template, you can call any Public procedures in LssMenu, from any other template, by setting a reference to LssMenu in that latter template.

    This reference can be set at design time in the VBE, rather than at runtime: with the second template (Lss_Summary) open in the VBE, go to Tools > References and scroll through the list of Available References until you locate LssMenu - the list will probably be very long, but if LssMenu is currently loaded, then it will appear somewhere in the list. Once you locate it, set a reference to it by clicking a checkmark next to it and OK out of the dialog.

    Once you've done that, you can call any public procedure that's in LssMenu from Lss_Summary, as if the procedure were in Lss_Summary - no need to use Application.Run.

    Here's an example of code in a procedure in a Letter template - the error handler calls an error handling procedure which is actually located in another, global template (this procedure is called "ErrorHandler", and takes as its arguments the error object, the name of the current code module and procedure) :

    <pre>On Error GoTo LetterHead_Err

    'code to do stuff is here

    LetterHead_Exit:
    Exit Sub
    LetterHead_Err:
    ErrorHandler Err, MODNAME & ".LetterHead"
    Resume LetterHead_Exit

    End Sub
    </pre>

    Gary

  7. #7
    New Lounger
    Join Date
    Feb 2001
    Location
    Jackson, Mississippi, USA
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks to everyone that responded...

    I did figure this out eventually, and as usual, it was a combination of things, so each one of your suggestions and comments were helpful to me.

    Thanks again.
    Ann

Posting Permissions

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