I have used shell scripting to copy and paste excel data in outlook body.
This preserves the format as well. Steps to replicate the process is as follows:-
Step 1 - Open a notepad and paste the below code and save the file with .ps1 extension
$x1 = New-Object -comobject Excel.Application
$UserWorkBook = $x1.Workbooks.Open(" excel path")
$UserWorksheet = $UserWorkBook.Worksheets.Item(1)
$UserWorksheet.activate()
$rgeSource=$UserWorksheet.range(“A1”,“D11”)
$rgeSource.Copy() | out-null
$Outlook = New-Object -comObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.Recipients.Add(“enter sender email”)
$Mail.Subject=“enter subject”
$oDoc = $Mail.GetInspector.WordEditor
$oRange = $oDoc.Range()
$oRange.InsertParagraph
$oRange.InsertBefore(“Hi Team,”)
$oRange.InsertParagraphAfter()
$oRange.InsertParagraphAfter()
$oRange.InsertAfter(" enter the mail body")
$oRange.InsertParagraphAfter()
$oRange.InsertParagraphAfter()
$oRange.Collapse($wdCollapseStart)
$oRange.Paste()
$oRange.Collapse($wdCollapseEnd)
$oRange.move(4,3)
$oRange.InsertParagraphAfter()
$oRange.InsertAfter(“Thanks & Regards,”)
$oRange.InsertParagraphAfter()
$Mail.Display()
$Mail.Send()
Step 2 - If you encounter the below error- “ps1 cannot be loaded because running scripts is disabled on this system.” then you need to create a .bat file using notepad to execute the shell script-
@echo off
color 1F
echo.
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File "shell script path "
:EOF
echo Waiting seconds
timeout /t 40 /nobreak > NUL
Step 3- You can then use start process activity in UiPath to execute the bat file.
The bat file calls and run the shell script which sends email.
Let me know if this helps.
Thanks & Regards,
Lipika