Group: microsoft.public.word.vba.general
From: "Shauna Kelly"
Date: Saturday, February 16, 2008 4:02 AM
Subject: Re: Generating Documents on the Fly

Hi Ron

How you go about extracting the bits of the old document depends, of
course, on what you need. If, for example, you needed to extract the
first paragraph of the old document, you could use something like this:

Sub CreateNewDoc()

Dim docOld As Word.Document
Dim docNew As Word.Document
Dim rngOld As Word.Range
Dim rngNew As Word.Range

Set docOld = ActiveDocument
Set docNew = Documents.Add(Template:="MyTemplate.dot")

Set rngOld = docOld.Paragraphs(1).Range

Set rngNew = docNew.Range
rngNew.Collapse wdCollapseEnd
rngNew.FormattedText = rngOld.FormattedText


docNew.SaveAs FileName:="MyNewFileName.doc"

End Sub


Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word



"Ron G" wrote in message
news:93D2A520-B613-4B44-BA6F-F85D6B57DA98@microsoft.com...
>I am looking for a way to extract certain sections out of one very long
> document to generate a seperate document based on answers the user
> will give
> to questions when the document is first opened. So basically I am
> trying to
> generate a document that is tailored to the users needs. Any help or
> suggestions would be greatly appreciated.
>
> Thanks


Safety Articles | Usenet Groups | Usenet News | Bluegrass