How do I make a single document from another 500 by appending cont

G

Guest

Hi there,
I wonder if you guys can help me... How do I make a single word document
from another let's say 500 or 1000 documents by appending their content? I
have one folder with more that 400 small word documents, smaller than 1/2
page, and I want to append them in a single file, programatically. It doesn't
matter the order of the documents that are appended.
Any help will be appreciated.
Thanks.
 
H

Helmut Weber

Hi Costi,

in principle like that:

Sub Macro3()
Dim strSourcePath As String
Dim strDocumToAdd As String
strSourcePath = "c:\test\word\"

strDocumToAdd = Dir(strSourcePath & "*.doc", vbNormal)
While strDocumToAdd <> ""
ActiveDocument.Bookmarks("\endofdoc").Select
Selection.InsertFile _
FileName:=strSourcePath & strDocumToAdd
ActiveDocument.Save
ActiveDocument.UndoClear
strDocumToAdd = Dir
Wend
End Sub



Make sure, that the actual doc is in a folder
different from the folder, where all the small docs are.

I've tried to keep it simple,
there are many other maybe faster ways.



--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
G

Graham Mayor

The boiler.dot add-in you can download from my web site will allow you to
assemble the documents in any order you like and choose whether you want
each in a new section before inserting them in the current document.

The following macro will simply insert each Word document, from a folder you
select, one after another. If there is no docu8ment open it will create one
based on normal.dot.

Note unless all the short documents are based on the same template, this
document will be a formatting jungle.

Sub BatchInsert()
Dim myFile As String
Dim PathToUse As String
Dim MyDoc As Document

With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
PathToUse = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With
If Documents.Count = 0 Then
Documents.Add
End If
If Left(PathToUse, 1) = Chr(34) Then
PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2)
End If
myFile = Dir$(PathToUse & "*.do?")
While myFile <> ""

Selection.InsertFile myFile

myFile = Dir$()
Wend
End Sub


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Guest

Hi guys,

Thanks a lot to both of you for your support. It went very well. It was
exactly what I needed.
Thanks again.

Best regards,
Costi ANDRITOIU
 
G

Guest

Thanks for your support. I managed to append all the docs in a single one.
Thanks again.

Best Regards,
Costi ANDRITOIU
 

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