Search code examples
vbaoutlookforwarding

Differences between when we manually forward and email versus when we use a macro to forward an email in outlook


I haven't noticed manually forwarding an email using outlook (2016) forward button is giving me different result from when I use a macro to forward it. Here is my macro:

Sub W()

Dim helpdeskaddress As String
Dim objMail As Outlook.MailItem
Dim strbody As String
Dim oldmsg As String
Dim senderaddress As String
Dim addresstype As Integer

' Set this variable as your helpdesk e-mail address
helpdeskaddress = "[email protected]"

Set objItem = GetCurrentItem()
Set objMail = objItem.Forward

' Sender E=mail Address
senderaddress = objItem.SenderEmailAddress

'Searches for @ in the email address to determine if it is an exchange user
addresstype = InStr(senderaddress, "@")

' If the address is an Exchange DN use the Senders Name
If addresstype = 0 Then
senderaddress = objItem.SenderName
End If

'adds the senders e-mail address as the created by object for the ticket and appends the message body
strbody = "#created by " & senderaddress & vbNewLine & vbNewLine & objItem.Body

objMail.To = "[email protected]"
objMail.Subject = objItem.Subject
objMail.Body = strbody

' remove the comment from below to display the message before sending
'objMail.Display

'Automatically Send the ticket
objMail.Send
MsgBox ("The email has been sent for verification. You may receive a report in a few moments.")

Set objItem = Nothing
Set objMail = Nothing
End Sub

and a function to obtain the current email object item:

Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
  Case "Explorer"
    Set GetCurrentItem = _
    objApp.ActiveExplorer.Selection.Item(1)
  Case "Inspector"
    Set GetCurrentItem = _
    objApp.ActiveInspector.CurrentItem
  Case Else
End Select
End Function

When I forward an email, I can see all images (linked to another website on the Internet) I am forwarding but when I use the following macro, all I see is the text inside the email. Is there anyway I can make the following macro to do the similar job as manually forwarding does?


Solution

  • To forward the original content, use HTMLBody instead of Body:

    strbody = "HTML-encoded content"
    
    objMail.HTMLBody = strbody & objMail.HTMLBody
    

    Sample HTML Format specific text in Outlook