Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Running a procedure in another document (VBA Word 2000)

    <P ID="edit" class=small>(Edited by TroyWells on 09-Oct-02 16:56. )</P>I've read through numerous posts on the subject, but I can't find exactly what I'm looking for. Sorry if I missed it somewhere in the deep recesses of this forum.

    I have a document with an attached template.

    I copy a module from the attached template to the document.

    How do I then call a procedure in the copied module in the document from a procedure in the attached template. (i.e. I want to make sure I'm not running the procedure from the attached template, but from the document.

    I know I could set a reference to the document, rename the module in the document, then call it, but I figure there has to be a better way. Surely there is a way to specify that I am calling the procedure from the document, not the procedure of the same name from the template.

    Isn't there?

    EDIT:
    Actually the above process does not work when the template is attached to the document because it cannot make a cyclical reference.

    I've also tried the following:

    Application.Run MacroName:=ActiveDocument.FullName & "UninstallProcedures.UninstallTemplate"

    but get Run-time error '-2147352573 (80020003)' Unable to run the specified macro.
    And I've also tried:

    With Dialogs(wdDialogToolsMacro)
    .Name = "UninstallProcedures.UninstallTemplate"
    .Run = True
    .Execute
    End With

    BUT I got Run-time error '5' Invalid procedure or argument. HOWEVER, the crazy thing is that it did run the macro named here. Why it gave the error, I'd sure like to know.

    Hope I haven't muddied the waters too much.

    Thanks!!
    Troy

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

    Re: Running a procedure in another document (VBA Word 2000)

    Troy,

    Sorry if you've explained this in an earlier thread which I've missed, but: why are you trying to do this? (or should I not dare ask?<g>) - the method you're trying sounds torturous - can there maybe be a different approach to what you need to do?

    If you're trying to unattach a template from a document which you've just created based on that template, you're likely to run into circularities whether you try to run the code from the template or the document. A procedure like this would best be located in a global template.

    Gary

  3. #3
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Running a procedure in another document (VBA Word 2000)

    Gary,
    You guessed it. I was trying to use code in the attached template to reset some shortcut menus (which you helped me do in my other post. Thanks again!!) in the active document and then unattach itself.

    I found ways of doing this without running code in the document. As long is attaching Normal (or another template) is the last step in the procedure, everything works fine.

    I do have a global template as one of the components I'm using that I could use if I need to. That's a good suggestion!! I just thought there out to be a way to call code in a document from code in the attached template. It makes sense (at least at my naive level) that it would be possible, but perhaps for other reasons its best to just avoid that altogether, as you said.

    If I ever can't use a global template, I may revisit this issue, but for now I think I have what I need.

    Thanks for your response!!
    Troy

Posting Permissions

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