Mail Merge from Excel error

suitcasejem

New Member
Joined
May 22, 2010
Messages
4
Hi guys,

I have made an Excel file in 2007 which sends data to a Word file via mail merge and everything works fine.

This is the code:

Code:
Sub JobCardMerge()
'
' JobCardMerge Macro

'Open Word and run the mail merge

MsgBox "When prompted, please select the sheet called 'Merge$'" & vbCrLf & "Save the job cards into your working folder.", vbOKOnly, "Reminder"

Dim MyPath As String
MyPath = ActiveWorkbook.Path

Application.ScreenUpdating = True
Application.DisplayAlerts = False
Set WordApp = CreateObject("Word.Application")

WordApp.Visible = True
WordApp.Documents.Open Filename:=MyPath & "\Job Card Template.doc"

With WordApp

.ActiveDocument.MailMerge.OpenDataSource Name:=MyPath & "\Project Details.xls" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=False, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", _
SQLStatement:="", SQLStatement1:=""

With .ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With

WordApp.Documents("Job Card Template.doc").Close SaveChanges:=wdDoNotSaveChanges

End With
'
End Sub


Unfortunately, the person who's going to use it only has 2003, and when I run it I get Run-time error '4198' (Command failed) and the following bit of code is highlighted, with the arrow pointing to the line with the SQLStatement bit:

Code:
ActiveDocument.MailMerge.OpenDataSource Name:=MyPath & "\Project Details.xls" _
, ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=False, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="", _
SQLStatement:="", SQLStatement1:=""

Does anyone have any ideas how to fix this?

Thanks,

Jem
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Well, as a dodgy fix for now, I've put the Microsoft Word 12.0 Object Library onto the computers running the program and that's fixed it. On another forum, someone suggested removing everything after "ActiveDocument.MailMerge.OpenDataSource Name:=MyPath & "\Project Details.xls", so I shall try that when I get chance to go back and look at it and see if that works.
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,925
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top