Home » excel » vba – Pasting formatted Excel range into Outlook message

vba – Pasting formatted Excel range into Outlook message

Posted by: admin April 23, 2020 Leave a comment

Questions:

I would like to paste a range of formatted Excel cells into an Outlook message.

The following code (that I lifted from various sources), runs without error and sends an empty message.

Sub SendMessage(SubjectText As String, Importance As OlImportance)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim iAddr As Integer, Col As Integer, SendLink As Boolean
'Dim Doc As Word.Document, wdRn As Word.Range
Dim Doc As Object, wdRn As Object

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

Set Doc = objOutlookMsg.GetInspector.WordEditor
'Set Doc = objOutlookMsg.ActiveInspector.WordEditor
Set wdRn = Doc.Range
wdRn.Paste

Set objOutlookRecip = objOutlookMsg.Recipients.Add("[email protected]")
objOutlookRecip.Type = 1
objOutlookMsg.Subject = SubjectText
objOutlookMsg.Importance = Importance

With objOutlookMsg
    For Each objOutlookRecip In .Recipients
        objOutlookRecip.Resolve
        ' Set the Subject, Body, and Importance of the message.
        '.Subject = "Coverage Requests"
        'objDrafts.GetFromClipboard
    Next
    .Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
How to&Answers:

I think you need to call .Save on your Mail Item (objOutlookMsg) after you’ve made all the changes.

Answer:

Put .Display before .Send,

Simple but Quick fix, your problem is the email is not refreshing with the pasted contents before it sends, forcing it to Display first gives it time…

Also make sure you have another macro which runs before this to Copy the Range into your clipboard…

Answer:

There is a button in excel to do this, “Send to mail recipent” its not normally on the ribbon.

You can also use the simple mapi built into office using the MailEnvelope in VBA

.. a good article on what you are trying to do http://www.rondebruin.nl/mail/folder3/mail4.htm