RPA — How to take a screenshot of an Email and insert it into Excel
While any RPA process, You may be in a situation where you might require to take a screenshot of an Email and insert it into an Excel file. Today I have come up with a tutorial, with the help of this you can achieve it in UiPath
Let’s divide this activity into two parts :
1. Screenshot of the Email
2. Inserting Screenshot in an Excel file
Screenshot of the Email:
Save the Email in your local Folder by using the “Save Mail Message” Activity
Use the “Start Process” activity to open the Email
Use “Take Screenshot” and “Save Image” activities
If required, You can close the opened mail and delete the saved mail
Inserting Screenshot in Excel
Once the screenshot is saved in Image format, We can insert it into an Excel file. I have used the “Invoke Code” activity for this task
Create two arguments and pass the Excel Workbook path and Screenshot path.
Code for “Invoke Code” Activity:
Dim excel_raw As Microsoft.Office.Interop.Excel.Application ‘Declare all required variables
Dim wb_c As Microsoft.Office.Interop.Excel.Workbook
Dim ws As Microsoft.Office.Interop.Excel.Worksheet
Dim ws_c As Microsoft.Office.Interop.Excel.Worksheet
excel_raw = New Microsoft.Office.Interop.Excel.ApplicationClass ‘Create the Excel Application Object
excel_raw.DisplayAlerts=False
excel_raw.Visible=True
wb_c = excel_raw.Workbooks.Open(wbpath) ‘Open the Excel File
ws=CType(wb_c.Sheets(“Email”),microsoft.Office.Interop.Excel.Worksheet)
ws.Activate
Dim oRange As Microsoft.Office.Interop.Excel.Range = ws.Range(“A3”) ‘It will place the Image in A3 cell
Dim left As Single=convert.ToSingle(oRange.Left)
Dim top As Single=convert.ToSingle(oRange.top)
Dim s As microsoft.Office.Interop.Excel.Shape=ws.shapes.AddPicture(imagepath,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoTrue,left,top,1000,750) ‘1000 and 750 are size of the image, Change it as per the requirement
wb_c.Save()
excel_raw.Quit()
Once the above steps are followed, It will work as expected.
Final Workflow:
Happy Automation !!
Follow me on LinkedIn: https://www.linkedin.com/in/santanbarnwal/
Subscribe to my YouTube channel: https://www.youtube.com/channel/UCoF8-B_MfOCL40szrorbtyQ
My Website: www.santanbarnwal.com
— Santan Barnwal