How to copy email body with signature images

My goal:

  • displaying 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 this? This code is (and should be) executed in excel. Below is a minimal example of my problem for testing, executing code from excel and adding a reference to the Microsoft Outlook Object Library; follow 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 can copy everything (including sig. Pictures) using the method mentioned in this SO question , so I have a workaround, but I'm wondering why a simple copy / paste of the HTML body doesn't work, since I'm just copying the HTML text.

+3


source to share


1 answer


Decision:



The signature image is attached to the post and hidden (as shown as the attached image when used .Display

). To copy the complete signature with images, I just need to copy all attachments.

+1


source







All Articles