moving between two open word documents in vb

E

Eddwads

I have a database of items to order. I've created a Word Template to create
a Purchase Order. When I fill a PO page I have to add a new page again which
gives me a new document. I want these all as one document. I want to create
the first page that summarizes all the P.O.s in the file and then append each
PO on this page. Then leave the one document open for the user to save,
print, etc.

I can see how to append one document to another, but how do I switch between
them in VB. I have not found a document name control to use. I create the po
page with

.Documents.Add Template:=strStartupPath & "\ETS Automation.dot" _
, NewTemplate:=False, DocumentType:=0

I have bookmarks in the template that I use to fill in the data. Also, how
do I erase the one page PO document after appending it to the main document?
Thanks Using office 2003
 
G

Graham Mayor

It sounds as though you are trying to compile all your orders in one
document. Why? Create a folder to store your orders and number them with the
number included in the filename for ease of reference. Having all the orders
in one document is simply storing up trouble for the future, and a corrupt
document means you lose the lot.

Create new documents from your template and keep them separate - you may
find http://www.gmayor.com/automatic_numbering_documents.htm useful.


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
F

Fumei2 via OfficeKB.com

Basically, I have to agree with Graham. Is there a real need to append these
into one document? Maybe there is, but:

"I can see how to append one document to another, but how do I switch between

them in VB. "

You can't. If you append the documents, then you have ONE document. There
is no switching, because the originals are gone. Unless of course you do as
Graham suggests and keep them as separate documents.

A document is a document is a document. Appending makes one document.

.Documents.Add Template:=strStartupPath & "\ETS Automation.dot" _
, NewTemplate:=False, DocumentType:=0

This creates a new document. Which seems to be fine. Once you have all of
your documents, yes, you could create another new document with your summary,
and then appending the actual documents. That would work. This would keep
your original (separate) documents files intact.

There are a number of ways to collate the documents. Either bring them in
explicitly. Or bring them in by reference using an INCLUDEFILE – or even
INCLUDETEXT – field.

“Also, how do I erase the one page PO document after appending it to the main
document?â€

What do you mean “erase�


Graham said:
It sounds as though you are trying to compile all your orders in one
document. Why? Create a folder to store your orders and number them with the
number included in the filename for ease of reference. Having all the orders
in one document is simply storing up trouble for the future, and a corrupt
document means you lose the lot.

Create new documents from your template and keep them separate - you may
find http://www.gmayor.com/automatic_numbering_documents.htm useful.
I have a database of items to order. I've created a Word Template to
create
[quoted text clipped - 21 lines]
document?
Thanks Using office 2003
 
F

Fumei2 via OfficeKB.com

To actually answer your subject question...

"moving between two open word documents in vb(a):

You use Document objects.

Dim ThisDoc As Document
Dim ThatDoc As Document

Set ThisDoc = ActiveDocument
Set ThatDoc = Documents("That OtherDoc.doc")

Voila. Two document objects, one the ActiveDocument, the other a document
named "That OtherDoc.doc" - which must be open.

Please note that you do NOT have to Activate a document object to perform
actions on it. If the other documents are open, AND they do not have tables:


Dim ThisDoc As Document
Dim ThatDoc As Document
Dim ThatSecondDoc As Document

Set ThisDoc = ActiveDocument
Set ThatDoc = Documents("TestDoc1.doc")
Set ThatSecondDoc = Documents("TestDoc2.doc")


' ThisDoc is STILL the ActiveDocument
ThisDoc.Range.InsertAfter ThatDoc.Range & _
vbCrLf & ThatSecondDoc.Range

This appends the Range of the other two documents to the end of the
ActiveDocument. Using ranges like this ONLY moves textual content, tables
will not be included.


If they DO have tables:


Dim ThisDoc As Document
Dim ThatDoc As Document
Dim ThatSecondDoc As Document
Dim r As Range

Set ThisDoc = ActiveDocument
Set ThatDoc = Documents("TestDoc1.doc")
Set ThatSecondDoc = Documents("TestDoc2.doc")
Set r = ThisDoc.Range

' ThisDoc is STILL the ActiveDocument

With r
.Collapse 0
ThatDoc.Range.Copy
.PasteAndFormat (wdFormatOriginalFormatting)
End With
Set r = ThisDoc.Range
With r
.Collapse 0
ThatSecondDoc.Range.Copy
.PasteAndFormat (wdFormatOriginalFormatting)
End With
Basically, I have to agree with Graham. Is there a real need to append these
into one document? Maybe there is, but:

"I can see how to append one document to another, but how do I switch between

them in VB. "

You can't. If you append the documents, then you have ONE document. There
is no switching, because the originals are gone. Unless of course you do as
Graham suggests and keep them as separate documents.

A document is a document is a document. Appending makes one document.

.Documents.Add Template:=strStartupPath & "\ETS Automation.dot" _
, NewTemplate:=False, DocumentType:=0

This creates a new document. Which seems to be fine. Once you have all of
your documents, yes, you could create another new document with your summary,
and then appending the actual documents. That would work. This would keep
your original (separate) documents files intact.

There are a number of ways to collate the documents. Either bring them in
explicitly. Or bring them in by reference using an INCLUDEFILE – or even
INCLUDETEXT – field.

“Also, how do I erase the one page PO document after appending it to the main
document?â€

What do you mean “erase�
It sounds as though you are trying to compile all your orders in one
document. Why? Create a folder to store your orders and number them with the
[quoted text clipped - 10 lines]
 

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