colinmitton
Technical User
I have a macro that runs from a word (2003) template. This macro runs a e-mail merge from an excel 2003 spreadsheet out via outlook 2003. Everything runs fine but no matter how many records it needs to merge (usually between 1 and 15) it always merges 46?
So for instance if I have 6 records to merge to email, it will merge and send out the 6 relevent emails then continue on until the 46th record, merging blank emails. They do not send out via outlook but it does take a while for this to happen so you sit their waiting a minute or two for no reason?
The Excel spreadsheet (source for the merge) is taken from a list thats been filtered to leave just the relevent records. These records have been copied and pasted (values only) to a fresh sheets which the records merge from. I have also checked the sheet to ensure there is nothing on the 46th / 47th row.
Any thoughts would be welcomed!
My code in the word template :
ActiveDocument.MailMerge.MainDocumentType = wdEMail
ActiveDocument.MailMerge.OpenDataSource Name:= _
"c:\temp\Unpaidbills.xls", ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=R:\Credit Control\Unpaid bills 14 days old to HOD.xls;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB
atabase Password="""";Jet OLEDB:Eng" _
, SQLStatement:="SELECT * FROM `Report$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
With ActiveDocument.MailMerge
.Destination = wdSendToEmail
.MailAddressFieldName = "HOD"
.MailSubject = "Unpaid Bills"
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
Application.Quit savechanges:=wdDoNotSaveChanges
Thanks folks....
So for instance if I have 6 records to merge to email, it will merge and send out the 6 relevent emails then continue on until the 46th record, merging blank emails. They do not send out via outlook but it does take a while for this to happen so you sit their waiting a minute or two for no reason?
The Excel spreadsheet (source for the merge) is taken from a list thats been filtered to leave just the relevent records. These records have been copied and pasted (values only) to a fresh sheets which the records merge from. I have also checked the sheet to ensure there is nothing on the 46th / 47th row.
Any thoughts would be welcomed!
My code in the word template :
ActiveDocument.MailMerge.MainDocumentType = wdEMail
ActiveDocument.MailMerge.OpenDataSource Name:= _
"c:\temp\Unpaidbills.xls", ConfirmConversions:=False, _
ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=R:\Credit Control\Unpaid bills 14 days old to HOD.xls;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB
, SQLStatement:="SELECT * FROM `Report$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess
With ActiveDocument.MailMerge
.Destination = wdSendToEmail
.MailAddressFieldName = "HOD"
.MailSubject = "Unpaid Bills"
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
Application.Quit savechanges:=wdDoNotSaveChanges
Thanks folks....