Forum Discussion
Using word Template as outlook mail body
When using a Word document as the body of an Outlook email through VBA, there can be some differences in behavior between using .Display and .Send. The issue you're facing might be related to the timing of sending the email. The .Display method allows you to review and make changes to the email before it is sent, while the .Send method sends the email immediately.
Here is a sample code that you can use as a reference:
Sub SendEmailWithWordBody()
Dim OutlookApp As Object
Dim OutlookMail As Object
Dim WordApp As Object
Dim WordDoc As Object
' Create a new instance of Outlook
Set OutlookApp = CreateObject("Outlook.Application")
' Create a new email
Set OutlookMail = OutlookApp.CreateItem(0)
' Create a new instance of Word
Set WordApp = CreateObject("Word.Application")
' Open your Word document
Set WordDoc = WordApp.Documents.Open("C:\Path\To\Your\Word\Document.docx")
' Copy the content from Word to Outlook
WordDoc.Content.Copy
OutlookMail.BodyFormat = 2 ' olFormatHTML
OutlookMail.HTMLBody = WordApp.Selection.HTML
' Additional email properties (To, Subject, etc.)
OutlookMail.To = "email address removed for privacy reasons"
OutlookMail.Subject = "Your Subject"
' Display or Send the email
' Uncomment one of the following lines
' OutlookMail.Display ' Use this line for previewing the email before sending
' Uncomment the next line for sending the email
' OutlookMail.Send
' Close the Word document and release objects
WordDoc.Close SaveChanges:=False
Set WordDoc = Nothing
Set WordApp = Nothing
' Release Outlook objects
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End SubIn this code:
- The Word content is copied using WordApp.Selection.HTML and pasted into the HTMLBody of the Outlook email.
- Make sure to replace "C:\Path\To\Your\Word\Document.docx", "email address removed for privacy reasons", and "Your Subject" with your actual file path, recipient's email address, and subject.
- The code is set up to either display the email or send it. Comment/uncomment the appropriate line based on your needs.
Remember to adjust the file path, recipient email, and subject as needed. Also, be cautious when using .Send, as it will send the email immediately without allowing you to review it.
If the issue persists, you may want to check for any error messages that might provide more information on what is going wrong during the .Send operation. Provide additional information about the office version, operating system, storage medium, etc. If possible the existing code. The text, steps and code were created with the help of AI.
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark as best response and Like it!
This will help all forum participants.