B
BAC
XP Pro;Office 2003 Pro
I receive 50 Excel Workbooks each quarter with one worksheet and between 10
and 1500 records on each worksheet. My task is to mail merge each workbook
with a sales promotion letter and save the merged letters into a .doc file
with the same name as the .xls from which the data is drawn.
Using DDE it takes about 1.5 -> 2 hours to run the mail merge with the
following Merge code in the Word Master Document:
Sub Merge_Letters()
.... Code...
For Each f In ff
If Right(f.Name, 4) = ".xls" Then
wd_name = Left(f.Name, Len(f.Name) - 4) & ".doc"
sh_name = "Sheet1"
On Error GoTo 0
try_Again:
With ActiveDocument.MailMerge
.OpenDataSource Name:=xl_files & f.Name, _
Connection:=[sh_name], SubType:=8
.Destination = wdSendToNewDocument
.Execute
End With 'Activedocument
.DDETerminateAll
.ActiveDocument.SaveAs xl_files & wd_name
.ActiveDocument.Close
End If 'Is .xls
Next f
....More Code...
End Sub
I have tried to replace the "With Mail Merge" DDE part above with:
With ActiveDocument.MailMerge
.OpenDataSource Name:=f.Name, _
Connection:= _
"DSN=Excel Files;DBQ=C:\WorkingFiles\BusinessLeasing\Execs\" &
f.Name &
";DefaultDir=C:\WorkingFiles\BusinessLeasing\Execs;DriverId=790;MaxBufferSize=2048;PageTimeout=5;" _
, SQLStatement:= _
"SELECT `'Sheet1$'`.Address, `'Sheet1$'`.City,
`'Sheet1$'`.`Client Manager`, `'Sheet1$'`.`Conf# Code`, `'Sheet1$'`.Contact,
`'Sheet1$'`.`Duns # `, `'Sheet1$'`.`Duns Number`, `'Sheet1$'`.F19,
`'Sheet1$'`" _
, SQLStatement1:= _
".`LEGAL NAME`, `'Sheet1$'`.`Market Executive`,
`'Sheet1$'`.Name, `'Sheet1$'`.Personalize, `'Sheet1$'`.Phone,
`'Sheet1$'`.Phone1, `'Sheet1$'`.RSM, `'Sheet1$'`.Score, `'Sheet1$'`.SIC4,
`'Sheet1$'`.State," _
, SubType:=wdMergeSubTypeOther
.Destination = wdSendToNewDocument
.Execute
End With 'Activedocument
.ActiveDocument.SaveAs xl_files & wd_name
.ActiveDocument.Close
But without success.
Is there another way to Access data for a Mail Merge that will speed up this
process, or can you offer any suggestions for fixing the SQL above so it'll
work?
TIA
BAC
I receive 50 Excel Workbooks each quarter with one worksheet and between 10
and 1500 records on each worksheet. My task is to mail merge each workbook
with a sales promotion letter and save the merged letters into a .doc file
with the same name as the .xls from which the data is drawn.
Using DDE it takes about 1.5 -> 2 hours to run the mail merge with the
following Merge code in the Word Master Document:
Sub Merge_Letters()
.... Code...
For Each f In ff
If Right(f.Name, 4) = ".xls" Then
wd_name = Left(f.Name, Len(f.Name) - 4) & ".doc"
sh_name = "Sheet1"
On Error GoTo 0
try_Again:
With ActiveDocument.MailMerge
.OpenDataSource Name:=xl_files & f.Name, _
Connection:=[sh_name], SubType:=8
.Destination = wdSendToNewDocument
.Execute
End With 'Activedocument
.DDETerminateAll
.ActiveDocument.SaveAs xl_files & wd_name
.ActiveDocument.Close
End If 'Is .xls
Next f
....More Code...
End Sub
I have tried to replace the "With Mail Merge" DDE part above with:
With ActiveDocument.MailMerge
.OpenDataSource Name:=f.Name, _
Connection:= _
"DSN=Excel Files;DBQ=C:\WorkingFiles\BusinessLeasing\Execs\" &
f.Name &
";DefaultDir=C:\WorkingFiles\BusinessLeasing\Execs;DriverId=790;MaxBufferSize=2048;PageTimeout=5;" _
, SQLStatement:= _
"SELECT `'Sheet1$'`.Address, `'Sheet1$'`.City,
`'Sheet1$'`.`Client Manager`, `'Sheet1$'`.`Conf# Code`, `'Sheet1$'`.Contact,
`'Sheet1$'`.`Duns # `, `'Sheet1$'`.`Duns Number`, `'Sheet1$'`.F19,
`'Sheet1$'`" _
, SQLStatement1:= _
".`LEGAL NAME`, `'Sheet1$'`.`Market Executive`,
`'Sheet1$'`.Name, `'Sheet1$'`.Personalize, `'Sheet1$'`.Phone,
`'Sheet1$'`.Phone1, `'Sheet1$'`.RSM, `'Sheet1$'`.Score, `'Sheet1$'`.SIC4,
`'Sheet1$'`.State," _
, SubType:=wdMergeSubTypeOther
.Destination = wdSendToNewDocument
.Execute
End With 'Activedocument
.ActiveDocument.SaveAs xl_files & wd_name
.ActiveDocument.Close
But without success.
Is there another way to Access data for a Mail Merge that will speed up this
process, or can you offer any suggestions for fixing the SQL above so it'll
work?
TIA
BAC