Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combining WORD 2000 Documents 1

Status
Not open for further replies.

pmcdaniel

Programmer
Feb 9, 2007
127
US
Hi,
Is there a way to combine several different WORD 2000 documents into one document without changing any of the formatting for any of the documents?

What I'm doing is opening a master document and working with tables, fields, bookmarks and saving the document under a different name - say Newdocument.doc. I'll be opening other master documents and doing the same but I need to combine the new documents into Newdocument.doc as I go - I'll just be adding each document onto the end. How do I do this?

We're using VB 6.0.

Thanks much.
 
Hi pcmcdaniel,

You can combinbe several documents into one through the judicious use of section breaks so that each added document retains its own formatting.

However, you also mention bookmarks. This is where it looks like you're going to come unstuck - a document can only have one instance of a given bookmark.

Cheers

[MS MVP - Word]
 
Okay, I know what section breaks are and have used them and I understand what you're saying and that's a good idea. However, I still don't know how to open one document and attach it to the end of another.
 
Have a look at the InsertFile method.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
InsertFile can have unwanted effects. Try it, but I suspect that you may have format issues.
I still don't know how to open one document and attach it to the end of another.
You do that by...doing that.
Code:
Dim file
Dim myFilePath As String
Dim r As Range
[COLOR=red]' set range object to document Range
Set r = ActiveDocument.Range
myFilePath = "c:\temp\temp2\"
file = Dir(myFilePath & "*.doc")
Do While file <> ""
   With r
[COLOR=red]' collapse range to the end of the doc[/color red]
      .Collapse Direction:=wdCollapseEnd
[COLOR=red]' insert a Section break[/color red]
      .InsertBreak Type:=wdSectionBreakNextPage
[COLOR=red]' insert the file[/color red]
      .InsertFile myFilePath & file
   End With
   file = Dir
Loop
It is important to note that InsertFile requires the full path, and Dir does not return that. You must add the Path.


The above code will append all .doc files (separated by a section break) in the c:\temp\temp2 folder to the active document.

If InsertFile does have unwanted effects, then you can open each file, grab its contents and bring it in.

faq219-2884

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top