Hi Patric.
Your template must be a *.doc E.g. Automerge.doc Open the file and place below i a Module. Notice if you will open the Automerge.doc you must push/keep SHIFT down. Place the Automerge.doc in the folder with your *.xls files. Prehaps you should split the files to a less number.
NB.: Sometime I do have probleme with the special signs we are using in my langauge, æ, ø, å. They are after mergin displayes as old "Japanese" letters and give no sense in the word.
Enjoy. 8-)
Option Explicit
'// General Sub autoopen() '// Joergen Bondesen, 20050920 Application.ScreenUpdating = False
Dim MyPath As String Dim MyFile As String Dim MyfileLen As Long Dim MyfileName As String
MyPath = CurDir
MyFile = Dir(MyPath & "\*.xls")
Do While MyFile <> ""
MyfileLen = Len(MyFile)
MyfileName = Left(MyFile, MyfileLen - 4)
'// Search With Application.FileSearch .FileName = MyfileName & ".doc" .LookIn = MyPath & "\" .Execute 'Exist goto line01 If .Execute() > 0 Then GoTo line01 End If End With
'// Merge SendKeys "{enter}" ActiveDocument.MailMerge.OpenDataSource _ Name:=MyPath & "\" & MyFile
With ActiveDocument.MailMerge .Destination = wdSendToNewDocument .SuppressBlankLines = True With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=True End With
'// Save merged doc ChangeFileOpenDirectory MyPath & "\" ActiveDocument.SaveAs FileName:=MyfileName _ & ".doc", FileFormat:= _ wdFormatDocument, AddToRecentFiles:=True
'// close merged file ActiveDocument.Close
line01:
'// Next MyFile = Dir Loop
'// Close merge doc without saving ''SendKeys "{Tab}", True SendKeys "%{F4}" SendKeys "%N"
Application.ScreenUpdating = True End Sub
-- Best Regards Joergen Bondesen
"Patrick" <Patrick[ at ]discussions.microsoft.com> wrote in message news:2875D664-8362-408F-85ED-9C1F2966C28B[ at ]microsoft.com...
[Quoted Text] > Hi! > > I apologize if this is answered in the forum, I have looked and can not > find > an appropriate answer. I have 218ish xls files that I need to merge with > a > word mail merge document and save the output .doc file with the same name. > i.e. > > test1.xls > test2.xls > test3.xls > > output to: > > test1.doc > test2.doc > test3.doc > > > Any help would be appreciated as I have been unable to do this with vb. > > Thank you! > > patrick
|