VBA

Moderators: PavlinII
Number of threads: 1614
Number of posts: 3000

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Word Mail Merge From an Excel Macro Posted by seawolf68 on 7 Jun 2007 at 5:32 AM
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 = ("\\fileserve\Timetndr\Service Level\Tommy Nobis\Thank 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("\\fileserve\Timetndr\Service Level\Tommy Nobis\Report Templates\Thank You Letter.doc")
WdDoc.Activate
WdDoc.MailMerge.OpenDataSource Name:="\\fileserve\Timetndr\Service Level\Tommy Nobis\Data Files\Thank 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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.