Search code examples
vbaoutlook

HTMLBody of e-mail loses its format when meeting text attached


I created VBA code that will attach something at the end of every e-mail.

With objItem
    .HTMLBody = .HTMLBody & "<p><p>" & TextID
End With

It usually works, but when I generate an e-mail from a meeting (the meeting minutes/summary) it loses its format. I did a test & even a direct .HTMLBody = .HTMLBody won't keep the format.

Original e-mail:
enter image description here

After I apply code.
enter image description here

My guess is appointment and meeting objects don't have the .HTMLBody property.

  1. Is my guess accurate?
  2. Is there a workaround that doesn't require a copy-paste from an e-mail or the inspector?
  3. Is there a way to detect that the e-mail comes from a meeting?

Solution

  • but I detected that, when I generate an e-mail from a meeting (the meeting minutes/summary) it basically loses its format

    Appointments (meetings) don't use the HTML based message bodies. Instead, the RTFBody property is available for them. You can use the StrConv function in Microsoft Visual Basic for Applications (VBA) or Visual Basic to convert an array of bytes to a string.

    You can use a low-level on which Outlook is built - Extended MAPI. The PR_HTML property (DASL is http://schemas.microsoft.com/mapi/proptag/0x10130102) returns the HTML markup unlike the OOM.

    But there is a universal solution - use the Word object model for dealing wit message bodies. See Chapter 17: Working with Item Bodies for more information.