Programming the subject line

W

WVeenendaal

I am merging an Excel file in a Word document and then emailing the resulting
document. I would like to individualize the email subject line in the header
with a field from the Excel file. How is this done
 
D

Doug Robbins

See the article "Mail Merge to E-mail with Attachments" at

http://word.mvps.org/FAQs/MailMerge/MergeWithAttachments.htm

Instead of using the InputBox as in the macro there to get the subject line,
use the mergefield that contains the subject in the catalog or directory
type mailmerge document and replace this section of the code:

With oItem
.Subject = mysubject
.Body = ActiveDocument.Content
Set Datarange = Maillist.Tables(1).Cell(Counter, 1).Range
Datarange.End = Datarange.End - 1
.To = Datarange
For i = 2 To Maillist.Tables(1).Columns.Count
Set Datarange = Maillist.Tables(1).Cell(Counter, i).Range
Datarange.End = Datarange.End - 1
.Attachments.Add Trim(Datarange.Text), olByValue, 1
Next i
.Send
End With

with:

With oItem
.Body = ActiveDocument.Content
Set Datarange = Maillist.Tables(1).Cell(Counter, 1).Range
Datarange.End = Datarange.End - 1
.To = Datarange
Set Datarange = Maillist.Tables(1).Cell(Counter, 2).Range 'Assumes
that the subject field is in the second column of the catalog
Datarange.End = Datarange.End - 1
.Subject = mysubject
.Send
End With


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top