Consulting

Results 1 to 2 of 2

Thread: Solved: Merging to Email with Attachments with document as body of message

  1. #1
    VBAX Contributor
    Joined
    Oct 2012
    Location
    Brisbane, Queensland, Australia
    Posts
    163
    Location

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

    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




    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

    [vba] 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
    [/vba]


    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

    [vba]Set objDoc = oOutlookApp.Session.GetItemFromID(strID)[/vba]

    is a MailItem.

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

  2. #2
    VBAX Contributor
    Joined
    Oct 2012
    Location
    Brisbane, Queensland, Australia
    Posts
    163
    Location
    I find this hard to believe, but it works if I replace:

    [VBA]With objDoc
    .Send
    End With
    [/VBA]

    with

    [VBA]With objDoc
    .sEnd
    End With
    [/VBA]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •