VB.net Automation

P

Paul

I am trying to create a document that is comprised of a
number of smaller documents based on a template. I am
able to create the documents one at a time and print one
at a time, however I would like to be able to append each
of the documents to a master document. This is all done
programmatically and the documents once instantiated are
never actually "Saved" as a file. I am using vb.net and am
stumped at being able to append a document (In ram Only)
to another document that is also only in ram. Someone
point me in the right direction. :)

Thanks,

-Paul
 
J

Jay Freedman

Hi, Paul,

I'll assume all the documents are based on the same template, so there
aren't any issues with styles that may have different definitions in
different documents...

Either create another new document to hold the compilation, or just tack
everything else onto the end of the first document. In either case, start by
declaring a Range object and assigning it to the insertion point at the end
of the compilation:

Set oRg = oFinalDoc.Range
oRg.Collapse(0) ' wdCollapseEnd

Then just squirt the formatted text of the next document into it:

oRg.FormattedText = oNextDoc.Range.FormattedText

If necessary, insert a section break at the end of oRg, collapse oRg to the
end of the document again, and you're ready to insert the next document.

This method won't bring in headers/footers, which you'll have to recreate in
the new location. If that's a problem, it might be easier to save the small
documents to disk temporarily and use the InsertFile method instead, then
discard the files.
 

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