Word Mail Merge From an Excel Macro - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Word Mail Merge From an Excel Macro

seawolf68seawolf68 Posts: 1Member
I am having a problem trying to do a mail merge from an Excel macro.

I am not able to specify whick sheet the merge should use. can anyone give me a hand on this?

Here is what I am doing:
fname = ("\fileserveTimetndrService LevelTommy NobisThank You Letter." + InputDate + ".doc")
Dim appWd As Word.Application
Dim WdDoc As Word.Document

Set appWd = CreateObject("Word.Application")
appWd.Visible = True
On Error Resume Next

On Error GoTo 0

With appWd
Set WdDoc = appWd.Documents.Open("\fileserveTimetndrService LevelTommy NobisReport TemplatesThank You Letter.doc")
WdDoc.MailMerge.OpenDataSource Name:="\fileserveTimetndrService LevelTommy NobisData FilesThank You Letter.xls", _
ReadOnly:=True, LinkToSource:=0, AddToRecentFiles:=False, _
PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _
Connection:="", SQLStatement:="", SQLStatement1:=""
With WdDoc.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
End With
ActiveDocument.SaveAs fname
End With
Set WdDoc = Nothing
Set appWd = Nothing
Sign In or Register to comment.