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!

Categories

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:
MailMerge:
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.Activate
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
.Execute
End With
ActiveDocument.SaveAs fname
End With
WdDoc.Close
Set WdDoc = Nothing
Set appWd = Nothing
Sign In or Register to comment.