View Single Post
  #9   Report Post  
Posted to microsoft.public.word.formatting.longdocs
Ricki Miles Ricki Miles is offline
external usenet poster
 
Posts: 50
Default Inserting many files into one document


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

"Jay Freedman" wrote in message
...
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



On Sun, 24 Feb 2008 11:37:19 -0600, "Suzanne S. Barnhill"

wrote:

Did you try the macro in the second article?

--
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA

"Ricki Miles" wrote in message
...
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

"Doug Robbins - Word MVP" wrote in message
...
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/Macros...tFileNames.htm

and

"Print all documents in a given folder to a single print file" at:

http://www.word.mvps.org/FAQs/Macros...DocsInFldr.htm




--
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

"Ricki Miles" wrote in message
...
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

"Jay Freedman" wrote in message
...
On Sat, 23 Feb 2008 12:33:45 -0600, "Ricki Miles"

wrote:

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


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/styl...xtChanges.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.