PDA

View Full Version : Solved: Create new document from a template



sandam
02-15-2005, 07:06 AM
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;?:bug:



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

Jacob Hilderbrand
02-15-2005, 07:24 AM
You already have Word open, so you don't need a new application (unless you want it). Try something like this.

Dim Doc As Document

Set Doc = Documents.Open MyFileName

'Do Stuff Here

Doc.Close False 'True to Save, False to not Save.

sandam
02-15-2005, 07:32 AM
Just to satisfy my curiosity - would changing the set statement to Set Doc = Documents.New MyFilename 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;?

Jacob Hilderbrand
02-15-2005, 07:41 AM
No, you can't do that. But if you Open a Template it will create a new Document based on that Template.

sandam
02-15-2005, 08:02 AM
cool. thanks for that

Anne Troy
02-15-2005, 03:12 PM
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! :)

Jacob Hilderbrand
02-15-2005, 04:18 PM
You're Welcome :beerchug:

Take Care

Anne: Thanks :)

sandam
02-16-2005, 02:34 AM
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 :yes