none
.Forward Not pulling through previous mail items formatting. RRS feed

  • Question

  • Hello All!

    My scripts purpose is to forward a selected mail item to a specified user with a pre-populated message.

    I have it all working however i have noticed that the new mail item created to be forwarded does not adopt the formatting from the original Email and it doesn't pull through images either.

    My code is:

    Sub ForwardItem()
    Dim oExplorer As Outlook.Explorer
    Dim oMail As Outlook.MailItem
    Dim oOldMail As Outlook.MailItem
    Dim oDialog As SelectNamesDialog
    Dim oFirstName As String
    Dim oFullName As String
    Dim varSplit As Variant


    Set oExplorer = Application.ActiveExplorer
    If oExplorer.Selection.Item(1).Class = olMail Then
    Set oOldMail = oExplorer.Selection.Item(1)
    Set oMail = oOldMail.Forward


    Set oDialog = Application.Session.GetSelectNamesDialog

        With oDialog
            .InitialAddressList = Application.Session.AddressLists("Global Address List")
            .ShowOnlyInitialAddressList = False
            If .Display Then
            End If
        End With
        

    On Error GoTo Release


    oMail.Recipients.Add (oDialog.Recipients(1).Address)
    oMail.Recipients.Item(1).Resolve
    If oMail.Recipients.Item(1).Resolved Then
    'MsgBox (oMail.Recipients.Item(1).Name)

    varSplit = Split(oMail.Recipients.Item(1).Name, " ", 2)
    oFirstName = varSplit(0)
    'MsgBox (oFirstName)

    oMail.Body = "Hi " + oFirstName + "," & vbCrLf & vbCrLf & "I have updated this ticket with the following from " + oOldMail.Sender + ". " & vbCrLf & vbCrLf & "Kind regards," & oMail.Body
    oMail.Display

    Else
    MsgBox "Could not resolve recipient name" & oMail.Recipients.Item(1).Name
    End If
    Else
    MsgBox "Not a mail item"
    End If
    Release:
        Set oMail = Nothing
        Set oExplorer = Nothing
    End Sub

    Any Assistance with this would be GREATLY appreciated.

    Kind regards, 

    Sam (struggling VBA user)

    Monday, May 19, 2014 4:04 PM

Answers

  • Hello Sam,

    The Body property doesn't contain any formatting. Instead, you need to use the HTMLBody property of the MailItem class for preserving the formatting. Here is what MSDN states:

    The HTMLBody property should be an HTML syntax string. Setting the HTMLBody property will always update the Body  property immediately.

    Monday, May 19, 2014 4:16 PM

All replies