I am trying to send Outlook emails from Excel VBA with the body of the email taken from a Word document. I can do that, my problem is the text pasted from the Word document is unformatted. It no longer keeps the bold, color, font, etc. of the original Word document. I am looking for help in getting the original formatting of the Word document pasted correctly in the body of the email.
I know I could use the .HTMLBODY and paste the html codes in a cell and then use the cell as the body of the email but that would not be user-friendly for my organization. I would like for the user the change the word document as needed and let the VBA pull from that Word document with the formatting the user used.
Below is the code that is working put pasting the word document content unformatted (I would like it to keep the formatting).
Thank you for your time.
P.S. I use the code from the post http://www.excelforum.com/excel-gene...ing-image.html which had a similar question. This post has been marked as solved but there is no reply of the solution found. I am not looking to paste image just keep the formatting (font, color, bold, etc.)
Sub CreateEmailBodyFromWord()
'Setup Outlook
Dim OutApp As Object
Dim OutMail As Object
'Setup word
Dim wd As Word.Application
Dim doc As Word.Document
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
'Get the word document
Set wd = CreateObject("Word.Application")
wd.Visible = True
Set doc = Documents.Open(Filename:="C:\Test\EmailBody_Template.docx", ReadOnly:=True)
'Copy the open document
doc.Content.Select
Word.Selection.Copy
'Setup the email
.To = "myname@gmail.com"
.Subject = "My subject"
.Body = Word.Selection
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
cleanup:
doc.Close
wd.Quit
Set doc = Nothing
Set OutApp = Nothing
Set wd = Nothing
Application.ScreenUpdating = True
End Sub
Bookmarks