My goal:
- display one mail to the user for editing
- create another mail with the same body content
My problem:
I can copy everything from the first mail except the image from my signature. Why is that? This code is (and needs to be) run in excel. Here is a minimal example of my problem for you to test, run code from excel and add a reference to Microsoft Outlook Object Library; go through code step by step with "F8" to see details.
Option Explicit
Dim objOutlook As Outlook.Application
Dim objOutlookMsgTemplate As Outlook.MailItem
Dim objOutlookMsg2 As Outlook.MailItem
Sub main()
CreateOutlookSession
CopyMailBody
End Sub
Function CreateOutlookSession()
On Error Resume Next
Set objOutlook = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set objOutlook = CreateObject("Outlook.Application")
End If
On Error GoTo 0
End Function
Function CopyMailBody()
Set objOutlookMsgTemplate = objOutlook.CreateItem(olMailItem)
Set objOutlookMsg2 = objOutlook.CreateItem(olMailItem)
With objOutlookMsg1
.Display 'this mail has a signature with pictures, if your default sig contains some
.HTMLBody = "signature below" & .HTMLBody
End With
With objOutlookMsg2
.HTMLBody = objOutlookMsgTemplate.HTMLBody 'this copies everything but pictures from my signature.. why?
.Display 'this mail does not contain the image from mail 1, just an area of the same size with a "file not found" message within
End With
End Function
I am able to copy everything (including sig. pictures) with the method mentioned in this SO question so I have a workaround, but I wonder why a simple copy/paste of the HTML body is not working, since i merely copy HTML text.