Mail Merge Macro to produce multiple documents

mcghue

New Member
Joined
Oct 28, 2014
Messages
1
Good day everyone. I am new to the site but have been playing around with excel/VBA etc for a while but have recently had an issue that for the life of me I cant resolve. I am trying to produce a document using a macro from excel to a template file using mail merge. All works fine until I have more than 1 line on my spreadsheet. I am using XP and office 2003.

Basically I want to create a document for each line on the spreadsheet. Below is the macro

Sub RunMailMergeRN()

Dim wdOutputName, wdInputName As String
FName = Sheets("Sheet1").Range("A2").Text
FName2 = Sheets("Sheet1").Range("B2").Text
wdOutputName = ThisWorkbook.Path & "\Updated\RN 0" & FName & " - MIN - " & FName2 & ".doc"

wdInputName = ThisWorkbook.Path & "\RN Blank Templatemail.doc"

' 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
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,215,514
Messages
6,125,273
Members
449,220
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top