PDA

View Full Version : Solved: Merging to Email with Attachments with document as body of message



Doug Robbins
06-13-2013, 10:50 PM
For a number of years now, I havemade available via the following page of my Windows Live SkyDrive a Merge ToolsAdd-in that allows Word to do a number of things with “Mail Merge” that itcannot do “out-of-the-box”



https://skydrive.live.com/?cid=5aedcb43615e886b#!/?cid=5AEDCB43615E886B!cid=5AEDCB43615E886B&id=5AEDCB43615E886B%21566 (https://skydrive.live.com/?cid=5aedcb43615e886b#!/?cid=5AEDCB43615E886B!cid=5AEDCB43615E886B&id=5AEDCB43615E886B%21566)




A number of the utilities includesending the results by email, either as PDF or Word Attachments or as the bodyof an email message. For the latter, Iwas using the following code, which I think I developed based on some of SueMosher’s work

Set objDoc = .MailEnvelope.Item
With objDoc
.To = MergeData(k + 1, Email)
.Subject = strSubject
For j = .Attachments.Count To 1 Step -1
.Attachments(j).Delete
Next j
If flagfields = True Then
For j = 0 To UBound(AttachmentFields)
.Attachments.Add MergeData(k + 1, AttachmentFields(j, 0))
Next j
End If
If flagfiles = True Then
For j = 0 To UBound(AttachmentFiles)
.Attachments.Add AttachmentFiles(j, 0)
Next j
End If
.Save
strID = .EntryID
End With
Set objDoc = Nothing
Set objDoc = oOutlookApp.Session.GetItemFromID(strID)
With objDoc
.Send
End With
Set objDoc = Nothing



I know that this did work when Ifirst developed it, but it is not something that I have used very much as mostof the time, I use the “Merge to Email as PDF Attachment” option To-day however, I was contacted by someone whowanted to merge with attachments with the merge document becoming the body ofthe email message and I have discovered that this no longer works. The messages are created and saved over thetop of one another in the Drafts folder, but nothing is ever sent.

I have confirmed that the NameType of the objDoc created by

Set objDoc = oOutlookApp.Session.GetItemFromID(strID)

is a MailItem.

Does anyone have any idea why this is failing?
Thanks in anticipation.

Doug Robbins
06-14-2013, 05:49 PM
I find this hard to believe, but it works if I replace:

With objDoc
.Send
End With


with

With objDoc
.sEnd
End With