ActiveDocument.MailMerge.Fields.Add Range:=WdDoc.Bookmarks(cell.Offset(0, 2).Value).Range, Name:=txt & cell.Offset(0, 3).Value
Sub DoMerge() Dim appWd As Word.Application Dim WdDoc As Word.Document Dim strBookFullName As String Dim cell As Excel.Range 'Dim wdFind As Object Dim txt As String 'Dim MyDoc As String strBookFullName = ActiveWorkbook.FullName Set appWd = CreateObject("Word.Application") appWd.Visible = True With appWd Set WdDoc = appWd.Documents.Open("C:\Users\Elmo\Documents\Aaron\2nd Project 2017\WorkingOn\VendorRebateClientDoc4March17_2.docx") WdDoc.Activate WdDoc.MailMerge.OpenDataSource Name:=(strBookFullName), _ ReadOnly:=True, LinkToSource:=0, AddToRecentFiles:=False, _ PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _ WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _ Connection:="", SQLStatement:="SELECT * FROM `MergeRange`", SQLStatement1:="" 'Set wdFind = appWd.Selection.Find 'finds text in word doc and replace with merge field For Each cell In Range("MergeText") 'wdFind.Text = cell.Value 'MyDoc = WdDoc.Range.Text txt = cell.Offset(0, 1).Value ActiveDocument.MailMerge.Fields.Add Range:=WdDoc.Bookmarks(cell.Offset(0, 2).Value).Range, Name:=txt & cell.Offset(0, 3).Value Next cell .ActiveDocument.MailMerge.Execute .ActiveDocument.SaveAs "C:\Users\Elmo\Documents\Aaron\From Client\Output\test2.docx" End With End Sub
Gain unlimited access to on-demand training courses with an Experts Exchange subscription.Get Access
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE
Connect with Certified Experts to gain insight and support on specific technology challenges including: