In stackoverflow there was a previous question:
βIs it possible to run MAIL MERGE from an excel macro (by clicking the button on the sheet) I have data sheets and want to export them to the new word doc.β The answer was dendarii 772.
We also had this need because we wanted to make life easier for volunteers with limited computer skills.
Unfortunately, the modified dendarii code exits with a 4198 runtime error in the .OpenDataSource statement.
Cindy Meister writes to Microsoft Office for the developer form> ..> Word 2010 VBA suggested that 4198 errors might be caused by synchronization issues. I gave it without success.
Mr Poulson, writing in Mr Excel, recommends that Snecz contributor compare his merging of VBA letters. OpenDataSource operation against writing a Word macro. What do the participants think? My .OpenDataSource line seems to be standard. My Excel datasource file has a title bar followed by two rows of data items.
We have Office 2010.
I would really appreciate any suggestions on how to fix 4198, and if anyone knows about general diagnostic procedures. We work for a two-person charity organization. Any help is appreciated!
Sub RunMerge() Dim wd As Object Dim wdocSource As Object Dim strWorkbookName As String On Error Resume Next Set wd = GetObject(, "Word.Application") If wd Is Nothing Then Set wd = CreateObject("Word.Application") End If On Error GoTo 0 Set wdocSource = wd.Documents.Open("C:\Users\george\Desktop\VBA Project\Mergeletter.docx") strWorkbookName = ThisWorkbook.Path & "\" & ThisWorkbook.Name wdocSource.MailMerge.MainDocumentType = wdFormLetters wdocSource.MailMerge.OpenDataSource _ Name:=strWorkbookName, _ AddToRecentFiles:=False, _ Revert:=False, _ Format:=wdOpenFormatAuto, _ Connection:="Data Source=" & strWorkbookName & ";Mode=Read", _ SQLStatement:="SELECT * FROM `Sheet1$`" With wdocSource.MailMerge .Destination=wdSendToNewDocument .SuppressBlankLines = True With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=False End With wd.Visible = True wdocSource.Close SaveChanges:=False Set wdocSource = Nothing Set wd = Nothing End Sub
source share