问题
I'm trying to send the content of a word document as the body of an outlook email, but it happens that the formats of the texts (Bold, color, etc) are lost after they are inserted into the email.
I have also tried using the word document as an Envelop item, and it did preserve the original format but the .Display method does not work under such circumstances.
Below are my codes
bodi = wdDoc3.Content
With wdApp.ActiveDocument
.SaveAs ThisWorkbook.Path & "./Past email/Email generated on" & "-" & Format(Date, "dd mmmm yyyy") & ".doc"
.Close
End With
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
.Display
End With
signature = Mail_Single.body
With Mail_Single
.To = arr2(2, 1)
.Subject = arr2(1, 1)
.CC = arr2(3, 1)
.Bcc = arr2(4, 1)
.body = bodi & vbNewLine & signature
and below is the code I found on the internet using the envelop method, but the .display or .visible method does not make the outlook window pop up. It just directly send out the email, which is not what I wanted.
set itm=wddoc3.mailenvelope.item
with itm
.to=""
.subject=""
.display
the .display here is not working
end with
How can I fix this or is there other ways to preserve the text format?
回答1:
The Body property of the MailItem class returns or sets a string representing the clear-text body of the Outlook item. To preserve any formatting you need to use the HTMLBody or Word Editor.
The Outlook object model provides three main ways for working item bodies:
- Body - a string representing the clear-text body of the Outlook item.
- HTMLBody - a string representing the HTML body of the specified item.
- Word editor - the Microsoft Word Document Object Model of the message being displayed. The WordEditor property of the Inspector class returns an instance of the Document class from the Word object model which you can use to set up the message body.
You can read more about all these ways in the Chapter 17: Working with Item Bodies.
So, you can easily use the Word editor to set the message body without loosing any formatting.
来源:https://stackoverflow.com/questions/31401883/preserve-text-format-when-sending-the-content-of-a-word-document-as-the-body-of