Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2008

Tip: Looking for answers? Try searching our database.

Generating Documents on the Fly

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ron G - 15 Feb 2008 05:23 GMT
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
Shauna Kelly - 16 Feb 2008 10:02 GMT
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

>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
[quoted text clipped - 5 lines]
>
> Thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.