Send Word document as email body

I already explained how to send emails automatically, but didn’t really focus on the content of the email. That is probably biggest problem of this method followers. In this article I’m going to show You how to cope with such issue and send Word document as email body.

The easiest way to have the content formatted properly is to copy text from Word and paste that to the created email. You cannot pass the content as string variable, because You will loose all the formatting.

Also there are other possibilities like adding HTML tags into the content, but this solution is good, when You have only 1 text. Not changeable, static, You know. And if it’s really long it would take a lot of time for tagging…

Anyway, back to the main topic, Word content to email body!

First of all, You need to copy the Word file content into the clipboard. To do that You need to create Word object and set the document – the equivalent of an Excel worksheet.

Set wd = CreateObject("Word.Application")
Set doc = wd.documents.Open("Word file path")

Then You can copy the content of the document and store it in clipboard.

doc.Content.Copy

Now comes the standard part of sending the email with a small modification. Instead of .Body You need to go to the WordEditor in your e-message.

Set editor = .GetInspector.WordEditor

After that just paste the text stored in clipboard by pasting that into the content of the editor object.

editor.Content.Paste

To this moment everything is easy and clear.

There goes the tricky part

Unfortunately using .Send method the content of the email body is empty. It appears that copy-pasting method is working only for .Display email method.

But nobody said that You can’t combine those 2 methods together.

.Display
.Send

It is causing a small flicker – just before sending, the email is popping up for a split second, but this is the only way to make it work.

Code

Option Explicit

Sub WordDocAsBody()

 Dim OutApp As Object, OutMail As Object
 Dim wd As Object, doc As Object, editor As Object

 Set wd = CreateObject("Word.Application")
 Set doc = wd.documents.Open("Word file path")
 doc.Content.Copy

 Set OutApp = CreateObject("Outlook.Application")
 Set OutMail = OutApp.CreateItem(0)

 With OutMail
     .To = "email address"
     .Subject = "subject"
     Set editor = .GetInspector.WordEditor
     editor.Content.Paste
     .Display
     .Send
 End With

 doc.Close 0
 Set OutMail = Nothing
 Set wd = Nothing
 Set OutApp = Nothing

 MsgBox "Done"

End Sub

That was the easiest way to have formatted text in the email body, the same way as in Word document. Although this has a small flicker, but I think we can consider this as the fastest and most comfortable way to send complex message using Outlook.

Tomasz Płociński

Author: Tomasz Płociński

I'm very advanced in VBA, Excel, also easily linking VBA with other Office applications (e.g. PowerPoint) and external applications (e.g. SAP). I take part also in RPA processes (WebQuery, DataCache, IBM Access Client Solutions) where I can also use my SQL basic skillset. I'm trying now to widen my knowledge into TypeScript/JavaScript direction.

One thought on “Send Word document as email body”

Leave a Reply

Your email address will not be published. Required fields are marked *