how to merge multiple word documents - many times!

R

robbieg

I have about 150 sets of 8 single page word documents that I want to merge
into single documents. Any ideas?
(i.e. I will end of with 150 documents each with 8 pages).

Thanks
 
R

robbieg

Thank you Graham. I don't think your add-in does I am am needing though.

I want to do the equivalent of 'Insert File' , eight times; and I want to do
that 150 times.

All the docs use the same style sheet - it is possible to concatenate Word
documents?

Thanks

RobbieG
 
G

Graham Mayor

It should be possible provided you can identify a means whereby the macro
can identify which eight documents are to be saved in which or the 150
files.
Or do you simply want to make 150 copies of the *same* eight documents, in
which case http://www.gmayor.com/Boiler.htm will join the documents into one
file, then you can use the following macro to create 150 versions of it. You
will need to change the path and filename lines

sPath = "D:\My Documents\Test\Merge\"
sFileName = "Filename

to reflect the path and filename you wish to use. The filename will have (1)
to (150) added in brackets before the extension.
If you want to save in Word 2007 format change doc to docx.

Sub Save150Copies()
Dim i As Long
Dim sFileName As String
Dim sPath As String
sPath = "D:\My Documents\Test\Merge\"
sFileName = "Filename"
With ActiveDocument
For i = 1 To 150
.SaveAs sPath & sFileName & _
"(" & i & ").doc", _
Addtorecentfiles:=False
Next i
End With
End Sub

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

robbieg

Thank you Graham. Sorry to be unclear.
There are 150 sets of 8 documents to join together. Each document is 1 page
long. They all use the same style sheet. So I would end up with 150
(different) documents each being 8 pages long.
I can put the 8 single pages into the same directory. Then I would have 150
directories, each with 8 docs in. Is that a bit clearer??
Thanks
 
D

Doug Robbins - Word MVP

How are the individual documents create and how are they named?

There is no doubt that vba can be used to combine documents, if the
individual documents that are to be combined can be identified.

I can't imagine that creating 150 separate folders to hold each set of eight
documents is the best way to go.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
F

Fumei2 via OfficeKB.com

Making that many folder is insane. I am not totally following this, but....

1. if the files are in the same folder

2. and you want to select 8 of them to do your file merging

Sub YaddaMultiLine()
Dim myFiles() As String
Dim myFilesListed As String
Dim j As Long
Dim var

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = True
.ButtonName = "OK"
.Title = "Select Parent Folder"
If .Show = 0 Then Exit Sub
If .SelectedItems.Count > 1 Then
For var = 1 To .SelectedItems.Count
ReDim Preserve myFiles(j)
myFiles(j) = .SelectedItems(var)
j = j + 1
Next
Else
myFiles(0) = .SelectedItems(1)
End If
If j <> 9 Then
MsgBox "HEY!!! You are supposed to select 8 files." & _
vbCrLf & "Macro will terminate. Try again."
Exit Sub
End If
End With
If j = 0 Then
myFilesListed = myFiles(0)
Else
For var = 0 To UBound(myFiles())
myFilesListed = myFilesListed & myFiles(var) & _
vbCrLf
Next
End If
MsgBox myFilesListed

End Sub

The code above insists on getting 8 file selected. You may not want that.
just remove it to get whatever number you want...except ONE. You cannot use
this 9as it is) to get just one file.

The point being is that you can build a list of the 8 files you want to grab,
and then process them. Like this:

Sub YaddaMultiLine()

' the other stuff to get the array of filenames

Dim r As Range

For var = 0 To Ubound(myFiles())
Set r = ActiveDocument.Range
With r
.Collapse 0
.InsertFile Filename:=myFiles(var)
End With
Next
End Sub

This process each of the arrayed filenames, and inserts it at the end of the
ActiveDocument. Do you next a page break? A Section break? Simply add one
for each iteration.

Gerry said:
How are the individual documents create and how are they named?

There is no doubt that vba can be used to combine documents, if the
individual documents that are to be combined can be identified.

I can't imagine that creating 150 separate folders to hold each set of eight
documents is the best way to go.
Thank you Graham. Sorry to be unclear.
There are 150 sets of 8 documents to join together. Each document is 1
[quoted text clipped - 68 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