Hi there,
We have an excel spreadsheet where the person adds a row at a time of data and they are looking for a macro that will open the word document and run the mail merge for that data only. I've got the macro working that will run a mail merge but it runs it for all the data. Is it possible to add in the criteria of the selected row of data? Note that the code is what i've picked up online and modified for my files so if it needs modifying at all, please let me know. Thanks! Brenda
We have an excel spreadsheet where the person adds a row at a time of data and they are looking for a macro that will open the word document and run the mail merge for that data only. I've got the macro working that will run a mail merge but it runs it for all the data. Is it possible to add in the criteria of the selected row of data? Note that the code is what i've picked up online and modified for my files so if it needs modifying at all, please let me know. Thanks! Brenda
Code:
Sub RunMailMerge()
Dim wdOutputName, wdInputName As String
wdOutputName = "c:\users\bbrown\desktop\testresult.docx"
wdInputName = "c:\users\bbrown\desktop\template.docx"
' open the mail merge layout file
Dim wdDoc As Object
Set wdDoc = GetObject(wdInputName, "Word.document")
wdDoc.Application.Visible = True
With wdDoc.MailMerge
.MainDocumentType = wdFormLetters
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute Pause:=False
End With
' show and save output file
wdDoc.Application.Visible = True
wdDoc.Application.ActiveDocument.SaveAs wdOutputName
' cleanup
wdDoc.Close SaveChanges:=False
Set wdDoc = Nothing
End Sub