Send an email with a picture embedded, rather than attached as a file

Hi everyone,

I want to send an email with the following image, not as an attachment. image is taken from excel data.

Is there a way to do it?
Thanks in advance,
Test.xlsx (11.4 KB)

@Tuannna1

Please try like this

Cheers

Hi @Anil_G
How can I get images from data excel ?
please check the attached file.

Thank,
Test.xlsx (11.4 KB)

@Tuannna1

You can follow the below steps

  1. Save excel as pdf
  1. Save pdf as image

Then you can use the above method to insert the generated image in email

Cheers

Hi,

How about using Modern SendEmail or Create HTML Content activity?
We can insert table from datatable to mail body, as the following.
(Please read datatable from Excel using ReadRange activity etc in advance)

https://docs.uipath.com/activities/docs/create-html-content

@Yoichi
Do you have an alternative method for adding an image generated from Excel data to the body of an email?
Thank you.

Hi,

How about the following custom activity?

Regards,

I have one activity available, but I am unsure about its safety.

Hi,

The following topic might also help you.

Regards,

1 Like

Sequence4.xaml (10.2 KB)
ConvertImageToBase64.xaml (6.0 KB)

  1. download sequence4.xaml and convertImagetoBase64.xaml to your project folder
  2. put below code in text file (vba.txt)
  3. open sequence4.xaml
    a. change imgPath to your own path (MUST BE JPG)
    image
    b. update send outlook activity and use imgHtmlString in body, remember to tick isBodyHTML
Function exportTableAsImage(imageFilePath As String)
    Sheets("data").Activate
    Dim rng As Range
    Set rng = Range("A1:J" & Range("A" & Rows.Count).End(xlUp).Row)
    Dim i As Integer
Dim intCount As Integer
Dim objPic As Shape
Dim objChart As Chart

Dim width As Integer, height As Integer
width = 1200 '10 inches
height = 360 '5 inches

     Call rng.CopyPicture(xlScreen, xlPicture)
    Dim Sheet2 As Worksheet
    Set Sheet2 = ActiveWorkbook.Sheets.Add

    'remove all previous shapes in sheet2
    intCount = Sheet2.Shapes.Count
        For i = 1 To intCount
            Sheet2.Shapes.Item(1).Delete
        Next i
    'create an empty chart in sheet2
    Sheet2.Shapes.AddChart
    'activate sheet2
    Sheet2.Activate
    'select the shape in sheet2
    Sheet2.Shapes.Item(1).Select
    Set objChart = ActiveChart
    'paste the range into the chart
    objChart.Paste
    objChart.Parent.width = width
objChart.Parent.height = height
    'save the chart as a JPEG
    objChart.Export (imageFilePath)
    
End Function



Sub TestIt()
exportTableAsImage ("a.jpg")

End Sub

image

1 Like

Hi @jack.chan

This solution works, but it may not be highly optimized for larger data sets exceeding 10 columns. To handle this, the resizing process should be customized in the vba.txt file. Nevertheless, I appreciate your enthusiastic help and will select your answer as the solution.

Also I have 1 other solution using:

Regards,
TuanNNA

1 Like

no problem, currently the height is set here (in vba code)
image

you can set it be dynamic and relative to # rows, but probably needs to do some testing to find optimal formula

roughly something like this
change the code:

width = 1200
height = 360

to

Dim width As Integer, height As Integer
width = 1200 

Dim numRows as integer
numRows = Range("A" & Rows.Count).End(xlUp).Row - 1
height = numRows * 40
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.