Generating Documents on the Fly

R

Ron G

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
 
S

Shauna Kelly

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top