Hi,
I'm a newbie when it comes to Word VBA and am trying to use something along the lines of the code below to do a mailmerge from Excel to a Word template containing multiple tables that contain merge fields.
Code:
endRowshtName = ActiveWorkbook.Worksheets("ns1").Range("A65536").End(xlUp).Row
endColshtName = ActiveWorkbook.Worksheets("ns1").Range("IV1").End(xlToLeft).Column
endColLettershtName = colNo2ColRef(endColshtName)
'Set shtNameRange = wb1.Worksheets("ns1").Rows("2:" & endRowshtName).Columns("A:" & endColLettershtName).Cells
wordTemplateFname = "C:\Users\Roy\Documents\Sandpit\Word Templates\Status_Report_Template 3.dotx"
ActiveDocument.MailMerge.MainDocumentType = wdDirectory
ActiveDocument.MailMerge.OpenDataSource Name:=ThisWorkbook.Path & "\" & ThisWorkbook.Name '& "!" & shtNameRange
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = endRowshtName
End With
.Execute Pause:=False
End With
This is currently creating multiple tables of the merge data instead of filling the rows of a specific table with the merge data. Is there any way for me to reference the Word table name and the MailMerge.OpenDataSource range to make this work? Or is populating Word tables beyond the limits of the mailmerge method? And if yes, what would be a good workaround?
Any help and advice would be much appreciated.
Thanks,
Roy