PDA

View Full Version : Insert All Documents into One



Anne Troy
08-16-2004, 09:27 AM
I need a sub to insert all files from *this* directory into *this document*.

So, all my files are in a directory.
I create a new file.
I put your sub in it.
I save it in the SAME directory.

I run the code.
This document gets all the other docs inserted into it using Insert-File, and in no particular order.

Thanks!!

Tommy
08-16-2004, 10:38 AM
Hi Dreamboat,
The below macro will insert all doc's in the docdirectory into the current doc. If you require more help let me know. If this does not work as required let me know. :)

Sub Macro1()
Dim DocDir As String
Dim LookFor As String
Dim FileName As String
DocDir = "c:\my documents\" '<--the directory to look in
LookFor = "*.doc"
FileName = Dir(DocDir & LookFor)
While FileName <> vbNullString
Selection.InsertFile FileName:=FileName, Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
FileName = Dir
Wend
ActiveDocument.SaveAs DocDir & "newfilename.doc" '<-- change this to a valid filename
End Sub


Happy Coding :type
Tommy

Anne Troy
08-16-2004, 10:43 AM
Cool! I'll send it to the user. :)