Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
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:
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.