Philippe.T
Board Regular
- Joined
- Jan 30, 2012
- Messages
- 94
- Office Version
- 2019
- 2016
- Platform
- Windows
I managed to create an outlook mail with an image of a given range. However, trying to insert 2 images of different ranges results in one of the images being displayed correctly while the other results in "The picture can't be displayed"
This is what I have so far.
This is what I have so far.
Code:
Sub test()
Dim OApp As Object
Dim OMail As Object
Dim signature As String
Set OApp = CreateObject("Outlook.Application")
Set OMail = OApp.CreateItem(0)
'------------------------------------------------------------------
'MAIL BODY
'------------------------------------------------------------------
Dim mailBody As String
mailBody = ""
'------------------------------------------------------------------
'CREATE MAIL IN OUTLOOK
'------------------------------------------------------------------
With OMail
.To = "TEST@GMAIL.COM"
.CC = ""
.BCC = ""
.Subject = "SUBJECT"
.Display
signature = .HTMLBody
'------------------------------------------------------------------
'IMAGE OF SELECTION 1ST
'------------------------------------------------------------------
Dim wdDoc As Word.Document
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
Set olApp = CreateObject("Outlook.Application")
Set wdDoc = OMail.GetInspector.WordEditor
wdDoc.Range.PasteAndFormat Type:=wdChartPicture
With wdDoc
.InlineShapes(1).Height = 170
End With
First = .HTMLBody
'------------------------------------------------------------------
'IMAGE OF SELECTION 2ND
'------------------------------------------------------------------
Sheets("X").Range("B2:CW132").CopyPicture Appearance:=xlScreen, Format:=xlPicture
Set olApp = CreateObject("Outlook.Application")
Set wdDoc = OMail.GetInspector.WordEditor
wdDoc.Range.PasteAndFormat Type:=wdChartPicture
With wdDoc
.InlineShapes(1).Height = 370
End With
'------------------------------------------------------------------
.HTMLBody = mailBody & vbNewLine & First & .HTMLBody & signature
End With
End Sub