View Single Post
  #12   Report Post  
Posted to microsoft.public.word.formatting.longdocs
Jay Freedman Jay Freedman is offline
external usenet poster
 
Posts: 9,854
Default Inserting many files into one document

Somewhere early in the thread we discussed adding "Page break before" to the
paragraph formatting of the heading that starts each page. That's much the
easiest way.

If the pages don't all start with a heading with the same style, then you can
make the macro insert a page break, although that's less reliable (for example,
if the page before the break comes to the bottom of the page, the page break
will cause a blank page). Replace the lines

If Err.Number = 0 Then
DestDoc.Save
Set oRg = DestDoc.Range
oRg.Collapse wdCollapseEnd
End If

with

If Err.Number = 0 Then
DestDoc.Save
Set oRg = DestDoc.Range
oRg.Collapse wdCollapseEnd
oRg.InsertBreak Type:=wdPageBreak
Set oRg = DestDoc.Range
oRg.Collapse wdCollapseEnd
End If

One more thing: This will leave a page break and a blank page at the end of the
last included document, which you should delete if you plan to print the
combined document.


On Mon, 25 Feb 2008 17:58:28 -0600, "Ricki Miles" wrote:

Jay, thank you so much for the information. I tried it and it works
perfectly. Where would I put in code for a hard page break between each
document?

Thanks again,

Ricki

"Jay Freedman" wrote in message
.. .
Yes, that's not hard. The idea is to combine the macro that lists the
files with
the macro that puts them together:

Sub CollectDocumentsIntoOne()
Dim DestDoc As Document
Dim oRg As Range
Dim MyPath As String
Dim MyName As String

'let user select a path
With Dialogs(wdDialogCopyFile)
If .Display() -1 Then Exit Sub
MyPath = .Directory
End With

'strip quotation marks from path

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If

Set DestDoc = Documents.Add
DestDoc.Save ' pop up SaveAs dialog

Set oRg = DestDoc.Range
oRg.Collapse wdCollapseEnd

'get files from the selected path
'and insert them into the doc
MyName = Dir$(MyPath & "*.doc")
Do While MyName ""
On Error Resume Next
oRg.InsertFile FileName:=MyPath & MyName, _
ConfirmConversions:=False, Link:=False
If Err.Number = 0 Then
DestDoc.Save
Set oRg = DestDoc.Range
oRg.Collapse wdCollapseEnd
End If
MyName = Dir
Loop

End Sub

This time you don't have to set up any file names or paths in the macro.
The
first dialog that appears when you run the macro (with the title "Copy",
unfortunately) lets you choose the folder containing the documents. Then a
second dialog ("Save As") lets you choose a folder and file name for the
combined document.


On Sun, 24 Feb 2008 16:02:28 -0600, "Ricki Miles"
wrote:
Thanks, Jay,

I tried the macro below and it works perfectly.

I do, however, have all the files in the correct order in a folder. Is it
possible to run a macro that loops through the filenames in the folder and
inserts them, rather than using the method below where you need the
filenames in an actual file?

Thanks again - much appreciated,

Ricki


--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.