In this article you will learn how to send a chart as picture using outlook from Excel Macro. As you know that in Outlook email, you can send an Image like a normal file attachment. In this case, receiver has to open the attachment to see the content. Since outlook supports HTML formatting of the email body, it is possible to paste the image in the body of the email itself. In this case, your image will be part of the body of the email. To view this receiver does not have to open any file.

Based on these two options available in Outlook, it is possible to send the Chart Image via Outlook using following two methods:

Sending Chart as an attachment to the email

Sending chart – embedded to the Outlook email body.

We will discuss about both the methods in detail here. Before we jump over to the VBA codes for those methods, let me explain you the trick which involved in achieving this task of sending your graph as a picture in your outlook email.

Steps to send Chart as Image in Outlook email

Let see some common steps which we are going to follow to send Excel graph as an Image in email.

Step 1. Save Chart as Image in your System

For sending the chart as an Image, it is important that we first save the Excel Chart as an Image somewhere in your local computer. Here in this example, I am storing the Image in temporary folder of your windows. You can read this article to know, how to find the special directories path of Windows using Excel VBA. Special directories like Desktop, My Documents, Temp Folders etc..

Step 2. Send the Image via email

Now send the Chart Image by either way from outlook. Read more about how to send emails from Outlook

Step 3. Now Delete the Image which was saved

At last delete the Chart Image from the temp folder where it was saved it. This logic, I have applied for both the methods mentioned below

Click here to read more about Sending emails using Excel VBA >>

 

Method 1: Sending Chart Image as an attachment in the mail

As explained earlier, in this methods, Chart image will be attached like any file attached to the email. You can refer the below image.

Chart Picture As an Attachment

Chart Image As an Attachment

VBA code to send Chart as a Picture in Your Outlook Email


Sub SendChart_As_Attachment_UsingOutlook()

    Dim olApp As Object
    Dim NewMail As Object
    Dim ChartName As String
    
    Set olApp = CreateObject("Outlook.Application")


    'fill in the file path/name of the gif file
    ChartName = Environ$("temp") & "\Chart1.gif"
           
    ActiveWorkbook.Worksheets("Sheet1").ChartObjects("Chart 1").Chart.Export _
    Filename:=ChartName, FilterName:="GIF"
    '**************************************************************
    'In the above line
    '   Sheet1 : Sheet Name where Chart is placed
    '   Chart 1: Chart Name which you want to sent in email.
    
    '   Note: To get the name of the Chart, select that particular
    '         chart and see in the left side of the formula bar.
    '***************************************************************
   
   ' Create a new mail message item.
    Set NewMail = olApp.CreateItem(0)
    With NewMail
        .Subject = "Please the attached Chart"
        .To = "abc@email.com"
        .Body = "Report is displayed below and chart is attached"
        .Attachments.Add ChartName
        .Send
    End With
    
    'Now delete the chart image from the temp folder
    'Kill ChartName

    'Release memory.
    Set olApp = Nothing
    Set NewMail = Nothing

End Sub

 

Method 2: Send the chart picture embedded in the Outlook email Body

As explained in the beginning of the article, in this method, Image is going to be part of the Email body. Email body format should be in HTML. Refer the below image to see how your image will look in your outlook email body.

Chart Embedded to message of Email

Chart Displayed as body of the Email

VBA Code to send Chart image embedded in the Outlook email Body


Sub SendChart_As_Body_UsingOutlook()

    Dim olApp As Object
    Dim NewMail As Object
    Dim ChartName As String
    
    Set olApp = CreateObject("Outlook.Application")


    'fill in the file path/name of the gif file
    ChartName = Environ$("temp") & "\Chart1.gif"
           
    ActiveWorkbook.Worksheets("Sheet1").ChartObjects("Chart 1").Chart.Export _
    Filename:=ChartName, FilterName:="GIF"
    '**************************************************************
    'In the above line
    '   Sheet1 : Sheet Name where Chart is placed
    '   Chart 1: Chart Name which you want to sent in email.
    
    '   Note: To get the name of the Chart, select that particular
    '         chart and see in the left side of the formula bar.
    '***************************************************************
   
   ' Create a new mail message item.
    Set NewMail = olApp.CreateItem(0)
    With NewMail
        .Subject = "Please the attached Chart"
        .To = "abc@email.com"
        
'       **************************************************
'       You can desing your HTML body for this email.
'       below HTML code will display the image in
'       Body of the email. It will not go in attachment.
'       **************************************************
        .HTMLBody =   "<img src=" & "'" & ChartName & "'>"
        .Send
    End With
    
    'Now delete the chart image from the temp folder
    'Kill ChartName

    'Release memory.
    Set olApp = Nothing
    Set NewMail = Nothing

End Sub