Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy multiple .DOC's into a single .DOC

Status
Not open for further replies.

ClarkJeff

Programmer
Feb 28, 2002
46
0
0
US
Anyone have a clue how to copy/merge multiple .DOC files into a single .DOC? Thanks.
 
Hi ClarkJeff,

I assume you want this to be done using automation. Here's a procedure I think might be what you are looking for:

Private Sub GetFiles()

Dim sFile As String
Dim sFiles() As String
Dim sPath As String
Dim intCount As Integer

ReDim sFiles(0)

'enter the path where the files to be inserted are located
sPath = "C:\FilesDir"

'check for files with extension "doc"
sFile = Dir(sPath & "\*.doc", vbNormal)

'collect found files
Do While sFile <> &quot;&quot;
If (GetAttr(sPath & &quot;\&quot; & sFile) And vbNormal) = vbNormal Then
ReDim Preserve sFiles(intCount)
sFiles(intCount) = sFile
intCount = intCount + 1
End If

sFile = Dir

Loop

'if found collection is not empty then insert file
'and enter a pagebreak after each insertion
If sFiles(0) <> &quot;&quot; Then


For intCount = 0 To UBound(sFiles())

ChangeFileOpenDirectory sPath & &quot;\&quot;
Selection.InsertFile FileName:=sFiles(intCount)
Selection.InsertBreak Type:=wdPageBreak

Next intCount

End If


End Sub


Regards,
Unica
 
This should get you started (it's kinda like a Merge :)):
Code:
Sub InsertDocumentAtEnd()
Selection.EndKey Unit:=wdStory
Selection.InsertFile FileName:=&quot;Document1.doc&quot;
Selection.EndKey Unit:=wdStory
Selection.InsertFile FileName:=&quot;Document2.doc&quot;
Selection.EndKey Unit:=wdStory
' etc. etc. etc. . . .
End Sub

I hope this helps you out!



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top