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:
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:
Does anyone have any ideas how to fix this?
Thanks,
Jem
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