MS Office Forum / Word / Long Documents / March 2008
Inserting many files into one document
|
|
Thread rating:  |
Ricki Miles - 23 Feb 2008 18:33 GMT I am working in Word 2003. I have over one thousand separate documents of one or two pages of text each. There are no graphics, tables, etc. What is the best way to combine them into a book consisting of one document? I don't want to use Master Document as I know it has many problems. I am thinking of using Insert File and making the formatting all the same. Any other suggestions?
TIA
Ricki
Jay Freedman - 23 Feb 2008 20:36 GMT >I am working in Word 2003. I have over one thousand separate documents of >one or two pages of text each. There are no graphics, tables, etc. What is [quoted text clipped - 6 lines] > >Ricki Not really a separate suggestion, but building on what you're already thinking...
Do you want each inserted document to start on a new page? There are a couple of ways to do that. The best, if each document starts with a heading formatted with the same style, is to add "Page break before" paragraph formatting to the definition of that style in the final document. The alternative is to insert a New Page section break between documents as you add them.
If you have a list of the file names of the separate documents, in the order that they should appear, then a macro could take that list as input and create the consolidated document. (If the documents aren't all on one folder, the list would have to include the full path to each one.) This would be a lot faster than building it by hand.
If the documents were all based on the same template and use the same style definitions, you shouldn't have any problems with formatting. If there could be styles with the same names but different sets of properties in different documents, though, you may run into trouble. See http://www.shaunakelly.com/word/styles/FormatOfTextChanges.html for the considerations.
-- 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.
Ricki Miles - 23 Feb 2008 22:29 GMT Thanks so much for your feedback. The documents should start on new pages in the finished combined document, so your suggestion of "page break before" for the heading style is perfect. I would like to create a macro that would insert each documents in the order in which they appear in the folder, but I don't know the VBA language to make it loop through. I'd appreciate help with that coding. Thanks again,
Ricki
>>I am working in Word 2003. I have over one thousand separate documents of >>one or two pages of text each. There are no graphics, tables, etc. What [quoted text clipped - 45 lines] > Email cannot be acknowledged; please post all follow-ups to the newsgroup > so all may benefit. Doug Robbins - Word MVP - 23 Feb 2008 23:17 GMT Take a look at the article "Insert into a document the names of all files in a selected folder" at:
http://www.word.mvps.org/FAQs/MacrosVBA/InsertFileNames.htm
and
"Print all documents in a given folder to a single print file" at:
http://www.word.mvps.org/FAQs/MacrosVBA/PrintAllDocsInFldr.htm
 Signature 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
> Thanks so much for your feedback. The documents should start on new pages > in the finished combined document, so your suggestion of "page break [quoted text clipped - 56 lines] >> Email cannot be acknowledged; please post all follow-ups to the newsgroup >> so all may benefit. Ricki Miles - 24 Feb 2008 16:45 GMT Thanks so much for the info!
Ricki
> Take a look at the article "Insert into a document the names of all files > in a selected folder" at: [quoted text clipped - 68 lines] >>> Email cannot be acknowledged; please post all follow-ups to the >>> newsgroup so all may benefit. Ricki Miles - 24 Feb 2008 16:50 GMT Hi Doug,
I just tried using the macro in the article below - it inserts the filenames into a document. What I need is the entire file text inserted into a document, then the next one, etc. to build a new document with the text of all the individual documents.
I'd appreciate some advice on how to create a macro to do this. Thanks again,
Ricki
> Take a look at the article "Insert into a document the names of all files > in a selected folder" at: [quoted text clipped - 68 lines] >>> Email cannot be acknowledged; please post all follow-ups to the >>> newsgroup so all may benefit. Suzanne S. Barnhill - 24 Feb 2008 17:37 GMT Did you try the macro in the second article?
 Signature Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA
> Hi Doug, > [quoted text clipped - 81 lines] >>>> Email cannot be acknowledged; please post all follow-ups to the >>>> newsgroup so all may benefit. Jay Freedman - 24 Feb 2008 19:21 GMT Suzanne, with apologies to you and Doug, the macro in the second article isn't going to help Ricki very much -- it prints the documents to a .prn file. If all you want is a printed copy of the combined document, then you can use the instructions in http://askbobrankin.com/printing_a_prn_file.html to print the .prn file. If you want an editable document, because you need to do formatting such as setting the heading style to "Page break before", then this macro is useless except as an example to someone who understands how to write and adapt a macro.
The following macro takes the list of document names and compiles those documents into one big document. You'll need to insert the real paths and file names into the macro where indicated by the three "set this" comments. Before you run this macro, read through the list of document names and make sure they're in the order you want them to appear in the final document.
Sub CollectDocumentsIntoOne() Dim DestDoc As Document Dim SrcDoc As Document Dim oRg As Range Dim NamesFile As String Dim DestName As String Dim oPara As Paragraph Dim MyPath As String Dim MyName As String ' set this to the full path and name of the file ' that contains the list of document names: NamesFile = "C:\SomeFolder\Includes.doc" ' set this to the path of the folder (with final backslash) ' that contains the files named in the list: MyPath = "C:\SomeFolder\Letters\" ' set this to where you want the final document ' to be saved DestName = "C:\SomeFolder\BigDoc.doc" Set SrcDoc = Documents.Open(NamesFile) Set DestDoc = Documents.Add DestDoc.SaveAs FileName:=DestName Set oRg = DestDoc.Range oRg.Collapse wdCollapseEnd For Each oPara In SrcDoc.Paragraphs If Len(oPara.Range.Text) > 5 Then ' name must be at least one char plus ".doc¶" MyName = oPara.Range.Text MyName = Left$(MyName, Len(MyName) - 1) 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 End If Next oPara SrcDoc.Close SaveChanges:=wdDoNotSaveChanges End Sub
>Did you try the macro in the second article? > [quoted text clipped - 76 lines] >>>>> http://www.shaunakelly.com/word/styles/FormatOfTextChanges.html for the >>>>> considerations. -- 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.
Ricki Miles - 24 Feb 2008 22:02 GMT 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
> Suzanne, with apologies to you and Doug, the macro in the second article > isn't [quoted text clipped - 176 lines] > Email cannot be acknowledged; please post all follow-ups to the newsgroup > so all may benefit. Jay Freedman - 25 Feb 2008 01:10 GMT 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.
>Thanks, Jay, > [quoted text clipped - 182 lines] >>>>>>> the >>>>>>> considerations. -- 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.
Ricki Miles - 25 Feb 2008 23:58 GMT 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
> Yes, that's not hard. The idea is to combine the macro that lists the > files with [quoted text clipped - 259 lines] > Email cannot be acknowledged; please post all follow-ups to the newsgroup > so all may benefit. Jay Freedman - 26 Feb 2008 01:53 GMT 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.
>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 [quoted text clipped - 70 lines] >>> >>>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.
Ricki Miles - 01 Mar 2008 22:34 GMT Thanks again for all the information,
Ricki
> Somewhere early in the thread we discussed adding "Page break before" to > the [quoted text clipped - 115 lines] > Email cannot be acknowledged; please post all follow-ups to the newsgroup > so all may benefit.
|
|
|