Jump to content

Copy from excel to email body


vick
 Share

Recommended Posts

Hi,

 

I have used Outlook UDF to create email.

Not in $bodyvar which is email body i need to copy something like $OWorkbook.ActiveSheet.Range("A1:F25").Copy and paste in $Bodyvar.

How i can do it pls?

thanks,

Link to comment
Share on other sites

Depends on the format of the Outlook mail you use. Is it HTML or RTF?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\1234".xlsx")

Global $oOutlook = _OL_Open()
Global $bodyvar=_Excel_RangeRead($oWorkbook, 1, "A1:F25")


_OL_Wrapper_SendMail(... )

this is my code. in excel i have chart and table which i want in body

Link to comment
Share on other sites

When using COM you do not automate the Outlook GUI but you use an API to directly interact with Outlook core.
I suggest to save the chart to a file and then imbed it into the mail body.
The example script for _OL_ItemCreate has an example how to add a Picture inline (Example 4).
 

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

This works for me, have fun off to have some zzzzzzzzz.

#include <Excel.au3>

$oExcel = _Excel_Open()
$oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Chart.xlsx")
$oRange = $oWorkbook.ActiveSheet.Range("A1:G34").Select
$oExcel.CopyObjectsWithCells = True
$oExcel.Selection.Copy

$oOutlook = ObjCreate("Outlook.Application")
$oMail = $oOutlook.CreateItem(0)

$oMail.Display
$oMail.To = "sample@example.com"
$oMail.Subject = "Sample Subject"
$oWordEditor = $oOutlook.ActiveInspector.wordEditor
$oMail.Body = "Hello" & @CRLF & "Please find charts above." & @CRLF & @CRLF & "Regards Subz"
$oWordEditor.Range(0, 0).Select
$oWordEditor.Application.Selection.Paste
$oMail.Display
Link to comment
Share on other sites

What is the value of @error after _Excel_BookOpen?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

$oExcel = _Excel_Open()
$oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Report.xlsx")
Sleep(5000)
$oRange = $oWorkbook.ActiveSheet.Range("A1:A5").Select
If @error Then
    MsgBox(0,"",@error)
EndIf
$oExcel.CopyObjectsWithCells = True
$oExcel.Selection.Copy

$oOutlook = ObjCreate("Outlook.Application")
$oMail = $oOutlook.CreateItem(0)

$oMail.Display
$oMail.To = "vp@xxx.com"
$oMail.Subject = "Sample Subject"
$oWordEditor = $oOutlook.ActiveInspector.wordEditor
$oMail.Body = "Hello" & @CRLF & "Please find charts above." & @CRLF & @CRLF & "Regards vp"
$oWordEditor.Range(0, 0).Select
$oWordEditor.Application.Selection.Paste
$oMail.Display

this is my script

Link to comment
Share on other sites

Your code works for me. Have you enabled macros and lowered excel security?

Try changing

$oRange = $oWorkbook.ActiveSheet.Range("A1:G34").Select

to

$oRange = $oWorkbook.Application.ActiveSheet.Range("A1:G34").Select
Link to comment
Share on other sites

Try:

#include <Excel.au3>

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\Chart.xlsx")
Local $oRange = $oWorkbook.ActiveSheet.Range("A1:G34").Select
    $oExcel.CopyObjectsWithCells = True
    $oExcel.Selection.Copy

Local $oOutlook = ObjCreate("Outlook.Application")
Local $oMail = $oOutlook.CreateItem(0)
    $oMail.Display
    $oMail.To = "sample@example.com"
    $oMail.Subject = "Sample Subject"

Local $sBodyHeader = "Hello" & @CRLF & @CRLF & "Please find charts below." & @CRLF & @CRLF
Local $sBodyFooter = @CRLF & @CRLF & "Regards Subz"

Local $oWordEditor = $oOutlook.ActiveInspector.wordEditor
    $oWordEditor.Range(0, 0).Select
    $oWordEditor.Application.Selection.TypeText($sBodyHeader)
    $oWordEditor.Application.Selection.Paste
    $oWordEditor.Application.Selection.TypeText($sBodyFooter)

$oMail.Display

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...