Merge multiple files into one
Stefan Blom wrote:
You can use Insert | File. If you want to preserve a link to the
original file, after selecting the file to insert, click the arrow
next to the Insert button and choose to "Insert as Link." This places
an INCLUDETEXT file in the target document; to update this field after
you've made changes to the original document(s), you can select the
entire document and press F9.
Stefan,
Thanks for the help. The file insert works the way I want, but there
are a couple of problems. I'm using sample data of 7 documents, Lesson
1.doc thru Lesson 7.doc. When I select all of the files using the shift
key, Word inserts all of the documents into one new blank document.
The problem I'm having is, they are inserted in the wrong order. the
order they are inserted is Lesson 7, 1, 2, 3, 4, 5, 6. Also there is no
page break between the documents. This works the same for Insert or
Insert Link.
What I did last night was record a macro and then add code around it for
what I needed. Here is the code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 7/25/2006 by Ronald W. Roberts
'
Dim MyName As String
Dim MyPath As String
MyPath = "D:\Computer Classes\RobCom\RobCom Introduction to Computers\"
ChangeFileOpenDirectory MyPath
MyPath = MyPath & "*.doc"
MyName = Dir(MyPath, vbNormal) 'Get first entry
Do While MyName "" ' Start the loop.
Documents.Open FileName:=MyName, ConfirmConversions:=False, _
ReadOnly:=False, AddToRecentFiles:=False, PasswordDocument:="", _
PasswordTemplate:="", Revert:=False, WritePasswordDocument:="", _
WritePasswordTemplate:="", Format:=wdOpenFormatAuto
Selection.WholeStory
Selection.Copy
Windows(1).Activate
Selection.PasteAndFormat (wdPasteDefault)
Selection.InsertBreak Type:=wdPageBreak
Windows(2).Activate
ActiveDocument.Close wdDoNotSaveChanges
MyName = Dir ' Get next entry.
Loop
MsgBox "Done", 48
End Sub
The first DIR command returns the first file. The second DIR at the
bottom of the loop without arguments, returns the next file that matches
the criteria. In the DO LOOP, when MyName is returned as a zero length
string, I know I'm done.
Ron
|