Results 1 to 10 of 10
  1. #1
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Macro calls: two docs created with diff templates (All)

    Hi

    Is it possible to call a macro from document to a macro in another document? For example

    Doc1 created using Doc1.dot template
    Doc2 created using Doc2.dot template
    Open both documents
    If doc1 needs to update to the Doc2 template
    Call a macro stored in Doc2 (template) from Doc1 to convert doc1 to doc2 'style'? (the macro will deal with all conversion issues)

    Thanks.
    Thanks.
    Robie

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro calls: two docs created with diff templates (All)

    Activate the Visual Basic Editor.
    Select the Doc2.dot template, i.e. the item labeled Project (Doc2).
    Change the (Name) property from Project to a unique name, e.g. MyProject, or Doc2Project.
    Save Doc2.dot (I don't know if it is essential now, but you'll have to do it anyway).
    Select the Doc1.dot template, i.e. the item labeled Project (Doc1).
    Select Tools | References...
    Tick the check box for the name you just assigned.
    Click OK.
    You can now call macros stored in Doc2.dot from (a document based on) Doc1.dot.

  3. #3
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro calls: two docs created with diff templates (All)

    Thanks very much. I have all you have specified.

    Sorry, stupid question - how do I invoke it? Does it need to be a unique name between the two templates and do I just invoke it as standard?

    Doc1
    Sub checkdoc
    ...
    ...
    if need2convert then
    call doc2 macro to start the conversion process

    Thanks.

    Robie
    Thanks.
    Robie

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro calls: two docs created with diff templates (All)

    I would give the macro a name that isn't used in the other template. You can then call it as if it were in the template itself: just use its name, preceded by Call if you prefer.

  5. #5
    Lounger
    Join Date
    Feb 2006
    Location
    Washington, District Of Columbia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro calls: two docs created with diff templates (All)

    Hi,

    How will I call it... what will the code look like?

    Thanks,
    Cris

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro calls: two docs created with diff templates (All)

    You can give a macro almost any name, provided that
    a) the name begins with a letter
    [img]/forums/images/smilies/cool.gif[/img] the name consists of letters, digits and underscores
    c) the name is not longer than 255 characters

    Say that you name a macro Happy2Run. You can call it from another macro simply as Happy2Run:

    Sub MyMacro()
    ...
    Happy2Run
    ...
    End Sub

    You can optionally precede the name with the keyword Call and a space:

    Sub MyMacro()
    ...
    Call Happy2Run
    ...
    End Sub

  7. #7
    Lounger
    Join Date
    Feb 2006
    Location
    Washington, District Of Columbia
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro calls: two docs created with diff templates (All)

    Thank you Hans [img]/forums/images/smilies/smile.gif[/img]

    One more question... will I be able to call an entire template but have it as a new document.

    Right now I have it set like this:

    Sub CallLetterhead()

    Documents.Open FileName:="c:Program FilesMicrosoft OfficeTemplatesLetter-FaxDWTLetterhead.dot"

    End Sub

    It opens up the template but I want it to open up the template as a new document using the letterhead template. Is that possible?

    Thanks again.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro calls: two docs created with diff templates (All)

    Yes, that is possible, by changing the line that opens the document to

    Documents.Add Template:="c:Program FilesMicrosoft OfficeTemplatesLetter-FaxDWTLetterhead.dot"

    Add creates a new document based on the specified template.

  9. #9
    4 Star Lounger
    Join Date
    Jan 2002
    Location
    London, Gtr London, England
    Posts
    416
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Macro calls: two docs created with diff templates (All)

    Hans

    This is going back about couple of weeks - its about calling a macro in Doc2 from Doc1.

    -------------------------------------------------------------------------------------------------------------------------------------
    Hans Wrote:
    Activate the Visual Basic Editor.
    Select the Doc2.dot template, i.e. the item labeled Project (Doc2).
    Change the (Name) property from Project to a unique name, e.g. MyProject, or Doc2Project.
    Save Doc2.dot (I don't know if it is essential now, but you'll have to do it anyway).
    Select the Doc1.dot template, i.e. the item labeled Project (Doc1).
    Select Tools | References...
    Tick the check box for the name you just assigned.

    Click OK.
    You can now call macros stored in Doc2.dot from (a document based on) Doc1.dot.

    Regards,
    Hans
    -----------------------------------------------------------------------------------------------------------------------

    Ok. The follow up question. I did the highlighted bit above as per your instructions. No problems. What I have found is that the referenced template is actually fixed, i.e. when I open a document based on doc1 (which references doc2 template), it opens the referenced template from a fixed location (this is my test area). I expected it to open the template from either User templates or Workgroup template setting under Options|File Locations.

    Now can I somehow reference a template so that its location is not fixed - it will load the second template from where it find it (Workgroup or User templates ares)? (The location originally was my test area & it seems that is when the second/referenced template is loaded from. In our case once the templates are tested they are then moved to the network location where anyone in the company can access them).

    Regards

    Robie
    Thanks.
    Robie

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Macro calls: two docs created with diff templates (All)

    References always use a hard-coded path, so basically, the answer is No.

Posting Permissions

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