Consulting

Results 1 to 8 of 8

Thread: Solved: Create new document from a template

  1. #1
    Knowledge Base Approver
    Space Cadet
    VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location

    Question Solved: Create new document from a template

    Hi again.

    With the current project (a couple posts for it alreeady) I am working on, I am required to create a fax cover sheet (I have a template for it) after a letter has been typed (and an option of send by fax) is selected. So essentially I'm looking and creating a document from a template within a macro, populating it with data from the letter document and then closing it again so that the user can either continue on the doc or close as needs be.

    I think it will be done using somthing like this - any advice ot tips would be appreciated.

    Thanks in advance

    Andrew;?


    [vba]
    Sub CreateFaxSheet
    Dim faxDoc as Word.Application

    faxDoc = CreateOject (<template name and location>,Word.Template)
    Call PopulateFaxSheet(LetterInformation)
    Call MakeFaxDocVisibleToEdit
    'and when they are done printing it
    faxDoc.Quit SaveChange:=True 'I will save the fax sheet using a custom save procedure)
    set faxDoc = Nothing
    End Sub
    [/vba]
    Last edited by sandam; 02-15-2005 at 07:07 AM. Reason: spelling

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You already have Word open, so you don't need a new application (unless you want it). Try something like this.
    [vba]
    Dim Doc As Document

    Set Doc = Documents.Open MyFileName

    'Do Stuff Here

    Doc.Close False 'True to Save, False to not Save.
    [/vba]

  3. #3
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location

    Talking Before I try it

    Just to satisfy my curiosity - would changing the set statement to [vba]Set Doc = Documents.New MyFilename[/vba] create a new document from a template. I'm almost certain it does but just thought i'd ask before i try it

    Thanks for your help once again

    Andrew;?
    Last edited by sandam; 02-15-2005 at 07:32 AM. Reason: spelling

  4. #4
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    No, you can't do that. But if you Open a Template it will create a new Document based on that Template.

  5. #5
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location

    Thumbs up

    cool. thanks for that

  6. #6
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Hi, sandam! You can help us by giving your questions meaningful titles. For instance, "I have little or no clue with this one" gives us little or no clue as to the question you have. I've changed the title to your question to something I hope is more meaningful. Just try to remember that some people only have a few minutes to pop in to answer questions, so meaningful titles helps them answer them more quickly. Also, if someone finds 10 threads here at VBAX when they do a Google search, a more meaningful title will help them more quickly find the answer. I hope you understand!
    ~Anne Troy

  7. #7
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    You're Welcome

    Take Care

    Anne: Thanks

  8. #8
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    Quote Originally Posted by Dreamboat
    Hi, sandam! You can help us by giving your questions meaningful titles. For instance, "I have little or no clue with this one" gives us little or no clue as to the question you have. I've changed the title to your question to something I hope is more meaningful. Just try to remember that some people only have a few minutes to pop in to answer questions, so meaningful titles helps them answer them more quickly. Also, if someone finds 10 threads here at VBAX when they do a Google search, a more meaningful title will help them more quickly find the answer. I hope you understand!
    No problem. Sorry bout that . Will try to do better

Posting Permissions

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