Multiple Word Document Objects in 1 project? Is it possible?

A

Adam Steiner

(Posted this earlier but it didn't seem to propogate, sorry if this is a
double).

Hi,

I have a word document which is about 20 pages long. It is 2 pages of form
fields which are then used to fill out the rest of the form. Unfortunately,
it takes a noticeable amount of time for the document to load and I will be
adding more documents (another 1-200 pages) in the near future.

What I was thinking of doing is having several documents, all part of the
same project (as different objects I guess). This way I could load the
documents as I need them and cut down on the load time (which I gather will
increase a lot more as I add these documents).

I haven't been able to find a way to add word documents to the project,
whenever I try it just adds another project that I can switch between. Can
anyone help, or does anyone have a different idea?

Thanks,

Adam
 
A

Adam Steiner

Graham Mayor said:
The technique described at http://www.gmayor.com/SelectFile.htm to insert
documents based on a form field selection may help.

--
Hi Graham,

That looks like it would work, although each file would be seperate. Out of
curiosity though, is it possible to have all of those files within a single
document, but as seperate document objects?
 
G

Graham Mayor

I am not sure what you are getting at here. You should aim to end up with a
single document, into which you can insert other documents (or parts of
other documents) using INCLUDETEXT fields as required.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Adam Steiner

My bad. I was misreading some of the things on the link you sent me. This
will work. I was thinking that when you're in the VB IDE it says
'ThisDocument' by Word objects, I was wondering if, from there, you could
put ThisDocument2 etc in the same project.

--Adam
 
J

Jay Freedman

Hi, Adam,

I think you've just been confused by some ill-considered terminology (a.k.a.
"Softyisms"). Word is *not* like Visual Studio -- it has no concept of
workspaces or projects with documents nested within them, or anything like
that. One document is one document, period. The document may contain links
that make it display parts of other documents, but they remain separate
documents all the same.

The VBA IDE (which is actually a separate program from Word) shows that each
template and document has a code module named ThisDocument, but that is
*not* a document -- it's just a container for code. You can name your code
modules pretty much anything you like, but they won't be documents at all,
let alone separate documents within a project.
 
A

Adam Steiner

(repost due to propogation issues)
Jay Freedman said:
Hi, Adam,

I think you've just been confused by some ill-considered terminology (a.k.a.
"Softyisms"). Word is *not* like Visual Studio -- it has no concept of
workspaces or projects with documents nested within them, or anything like
that. One document is one document, period. The document may contain links
that make it display parts of other documents, but they remain separate
documents all the same.

The VBA IDE (which is actually a separate program from Word) shows that each
template and document has a code module named ThisDocument, but that is
*not* a document -- it's just a container for code. You can name your code
modules pretty much anything you like, but they won't be documents at all,
let alone separate documents within a project.

Jay,

Aha, now it makes sense. I had been under the impression that each module
(ThisDocument) represented an actual document in addition to the code.
Would you be able to point me in a direction of a website which discusses
how to use the Word document object outside of Word? Such as if I were to
use Visual Studio to write an app that contained multiple documents (which I
may do now).

Thanks
Adam
 
J

Jay Freedman

Adam Steiner said:
Jay,

Aha, now it makes sense. I had been under the impression that each module
(ThisDocument) represented an actual document in addition to the code.
Would you be able to point me in a direction of a website which discusses
how to use the Word document object outside of Word? Such as if I were to
use Visual Studio to write an app that contained multiple documents (which I
may do now).

Thanks
Adam

I don't recall seeing anything that addresses the issue head-on, but
here are a couple of pages on the MVP site that show samples in the
course of discussing other topics:

http://www.word.mvps.org/faqs/interdev/EarlyvsLateBinding.htm
http://www.word.mvps.org/faqs/interdev/WordUsesSameInstance.htm
http://www.word.mvps.org/FAQs/InterDev/ControlWordFromXL.htm

Creating and using a Word object from standalone VB is very much the
same as doing it in VBA within another Office app such as Excel. And
once you have a Word object, you use the methods and properties of the
object model just as if you were in Word VBA.

Before you jump into this with both feet, though, figure out whether
what you want can be done entirely within Word. A single macro can
open and manipulate two, three, or more documents simultaneously, just
not in the way you were thinking before. For example, this dumb little
macro opens an existing file, creates two new blank documents, and
makes copies of the first paragraph of the first file in the other
two. When the macro finishes, you can use the Window menu to visit
each document and verify that it worked.

Sub MultiDocSample()
Dim SourceDoc As Document
Dim Target1 As Document, Target2 As Document
Dim SourceRg As Range, TargetRg As Range

' on error goto bye

' open existing doc
Set SourceDoc = Documents.Open("C:\temp\test.doc")
' make 2 new blank docs
Set Target1 = Documents.Add ' default Normal.dot
Set Target2 = Documents.Add ' default Normal.dot

' point to 1st paragraph of source
Set SourceRg = SourceDoc.Paragraphs(1).Range

' point to Target1 and copy source there
Set TargetRg = Target1.Range
TargetRg.FormattedText = SourceRg.FormattedText

' point to Target2 and copy source there
Set TargetRg = Target2.Range
TargetRg.FormattedText = SourceRg.FormattedText

bye:
' clean up
Set SourceDoc = Nothing
Set Target1 = Nothing
Set Target2 = Nothing
Set SourceRg = Nothing
Set TargetRg = Nothing
End Sub
 

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