0

I have an Excel with an embedded image.

How can I send it by mail using the name of the image? I do not want to send it attached, I want to embed it in the html of the mail. It's possible?

Thank you very much in advance

An example code:

With objMail
       'Set body format to HTML
       .BodyFormat = olFormatHTML

       .To = Sheet3.Range(inTo)
       If (inAttach1 <> "") Then .Attachments.Add inAttach1
       If (inAttach2 <> "") Then .Attachments.Add inAttach2
       If (Sheet3.Range(inCC) <> "") Then .CC = Sheet3.Range(inCC)

       sBody = Sheet1.Range("B2").Value
       '----insert Name
       iPos = InStr(1, sBody, "[FirstName]", vbTextCompare)
       iPos2 = iPos + Len("[FirstName]")
       sText1 = Mid(sBody, 1, iPos - 1)
       sText2 = Mid(sBody, iPos2, Len(sBody) - iPos2 + 1)
       sBody = sText1 & Sheet3.Range(inName) & sText2


       .Subject = inSubj
       .SentOnBehalfOfName = inFrom
       .HTMLBody = sBody
       'Importancia mail
       '.Importance = olImportanceHigh
       .sEnd
    End With
Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Igor
  • 205
  • 1
  • 8
  • 19
  • It is possible. You say you "do not want to send it attached"...so you mean you want to base64 encode the image I'm guessing. Fortunately, this SO post demonstartes methods for the reliable (send as attachment" method and the less reliable base64 encoding method: https://stackoverflow.com/questions/9110091/base64-encoded-images-in-email-signatures – Tim Dec 27 '19 at 17:08
  • @JGFMK thanks but is not my question – Igor Dec 30 '19 at 14:16
  • @Tim I have put code, how can I add the picture of an Excel sheet? Is not an online picture, is from the Excel sheet – Igor Dec 30 '19 at 14:22

2 Answers2

0

This might work for you: http://www.rondebruin.nl/win/s1/outlook/bmail3.htm

You can send a worksheet or a selection as the body of an email, and it will include any applicable images(on the worksheet or in the selected area).

Sub Send_Selection_Or_ActiveSheet_with_MailEnvelope()
'Working in Excel 2002-2016
    Dim Sendrng As Range

    On Error GoTo StopMacro

    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    'Note: if the selection is one cell it will send the whole worksheet
    Set Sendrng = Selection

    'Create the mail and send it
    With Sendrng

        ActiveWorkbook.EnvelopeVisible = True
        With .Parent.MailEnvelope

            ' Set the optional introduction field thats adds
            ' some header text to the email body.
            .Introduction = "This is a test mail."

            With .Item
                .To = "ron@debruin.nl"
                .CC = ""
                .BCC = ""
                .Subject = "My subject"
                .Send
            End With

        End With
    End With

StopMacro:
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
    ActiveWorkbook.EnvelopeVisible = False

End Sub
AirWreck
  • 15
  • 7
0

Create an attachment and set the PR_ATTACH_CONTENT_ID property (DASL name "http://schemas.microsoft.com/mapi/proptag/0x3712001F") using Attachment.PropertyAccessor.

Your HTML body (MailItem.HTMLBody property) would then need to reference that image attachment through the cid:

img src="cid:xyz"

where xyz is the value of the PR_ATTACH_CONTENT_ID property.

Look at an existing message with OutlookSpy (I am its author) - click IMessage button.

attachment = mailitem.Attachments.Add("c:\temp\MyPicture.jpg")
attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "MyId1")
mailitem.HTMLBody = "<html><body>Test image <img src=""cid:MyId1""></body></html>"
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78