vick Posted April 18, 2018 Share Posted April 18, 2018 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 More sharing options...
Jfish Posted April 18, 2018 Share Posted April 18, 2018 Try using the Excel UDF and the _Excel_RangeRead function. Then it is $bodyvar=_Excel_RangeRead([your arguments here) Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
vick Posted April 18, 2018 Author Share Posted April 18, 2018 Hi, I am getting this error:Variable used without being declared.: Also excel has chart which i want to copy in body. Link to comment Share on other sites More sharing options...
Subz Posted April 18, 2018 Share Posted April 18, 2018 Do you have an example Excel spreadsheet + your Autoit code we can look at? Link to comment Share on other sites More sharing options...
water Posted April 18, 2018 Share Posted April 18, 2018 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
vick Posted April 18, 2018 Author Share Posted April 18, 2018 html Link to comment Share on other sites More sharing options...
vick Posted April 18, 2018 Author Share Posted April 18, 2018 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 More sharing options...
water Posted April 18, 2018 Share Posted April 18, 2018 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
vick Posted April 18, 2018 Author Share Posted April 18, 2018 Hi, I saw _OL_ItemCreate function but do not see any example. how to add excel stuff when create email. Sorry I am not that Pro who can understand quickly. Link to comment Share on other sites More sharing options...
Subz Posted April 18, 2018 Share Posted April 18, 2018 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 More sharing options...
vick Posted April 18, 2018 Author Share Posted April 18, 2018 thanks Man. I will try and update you. Link to comment Share on other sites More sharing options...
vick Posted April 18, 2018 Author Share Posted April 18, 2018 Hi, I am getting this error Variable must be of type "Object" at this line: $oRange = $oWorkbook.ActiveSheet.Range("A1:G34").Select idea? Link to comment Share on other sites More sharing options...
water Posted April 18, 2018 Share Posted April 18, 2018 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 - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
vick Posted April 18, 2018 Author Share Posted April 18, 2018 I am not getting in @error anything but in console i got error Variable must be of type "Object" Link to comment Share on other sites More sharing options...
vick Posted April 18, 2018 Author Share Posted April 18, 2018 $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 More sharing options...
Juvigy Posted April 20, 2018 Share Posted April 20, 2018 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 More sharing options...
vick Posted April 20, 2018 Author Share Posted April 20, 2018 Thanks everyone for support. It works now. Link to comment Share on other sites More sharing options...
vick Posted April 20, 2018 Author Share Posted April 20, 2018 hi, i found one issue here that what i put in email body like text "Hello" & @CRLF & "Please find charts above." & @CRLF & @CRLF & "Regards vp" goes always after my copy part from excel. i want it in first line then paste. How i can do it pls? Link to comment Share on other sites More sharing options...
Subz Posted April 20, 2018 Share Posted April 20, 2018 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 More sharing options...
vick Posted April 22, 2018 Author Share Posted April 22, 2018 thank you very much sir Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now