Home > Software engineering >  How to add picture to outlook of specific cells (VBA)
How to add picture to outlook of specific cells (VBA)

Time:07-13

So,

I'm currently adding a "Send email" button to a working sheet and want to add a picture to the outlook email. The picture is a graph which gets updated every week.

It looks like this currently and guess i have to make a function somewhere in the body, wherever is suitable for the output:

Sub Create_Email()

'Define outlook variables
Dim OutApp As Object
Dim OutMail As Object

'Allocated
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

Dim NextParagraph As String

NextParagraph = vbNewLine & vbNewLine

'Inside the with box is what we send
With OutMail
    .To = "[email protected]"
    '.cc =
    '.bcc =
    .Subject = "Let us see if this will all show in the subject line"
    .Body = "Good morning everyone," & NextParagraph & "The Monday Morning Report is attached." & NextParagraph & _
                        "Comps are"
    
    
    .Display
End With
        
End Sub

Hope any of you are able to help out :-)

CodePudding user response:

You can use GetInspector.WordEditor to edit mail object and insert image using MS Word object model and insert picture with Shapes.AddPicture

Dim myInspector As Object
Dim wdDoc As Object
Dim myitem As Object
 
Set myitem = CreateObject("Outlook.Application").CreateItem(0)
Set myInspector = myitem.GetInspector
Set wdDoc = myInspector.WordEditor

CodePudding user response:

You can save the image as file, add it as an attachment, and reference it in the HTMLBody property instead of using the plain-text Body.

See https://stackoverflow.com/a/17197140/332059

  • Related