taurus905 Posted March 15, 2007 Share Posted March 15, 2007 As the title states, I am trying to use COM to paste the contents of an existing word document in to the body of an email in Outlook. I know this may be really simple, (I am hoping anyway) but the solution is aluding me at the moment. Any help is appreciated. taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted March 15, 2007 Moderators Share Posted March 15, 2007 I haven't gone through it personally, but have you sifted through big_daddy's word automation library to see if anything there might help?http://www.autoitscript.com/forum/index.php?showtopic=30461 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
taurus905 Posted March 16, 2007 Author Share Posted March 16, 2007 I haven't gone through it personally, but have you sifted through big_daddy's word automation library to see if anything there might help?http://www.autoitscript.com/forum/index.php?showtopic=30461SmOke_N,Thanks for the suggestion. I looked through big_daddy's thread and could not find anything I needed.Another thing I would like to do is use COM to attach a document to an email created in Outlook.I will keep seaching and hope that someone knows the simple commands I need.Thanks again.taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
taurus905 Posted March 16, 2007 Author Share Posted March 16, 2007 I found the command to attach a file: $oMail.Attachments.Add("C:\Memo.doc") Now I just need something like this: $oMail.Body("C:\Letter.doc") But it doesn't work. Any ideas? "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
DaleHohm Posted March 16, 2007 Share Posted March 16, 2007 (edited) Are you trying to automate CDO or Outlook? Dale Edit: Oh... I just reread your topic title... Outlook... Ok Edited March 16, 2007 by DaleHohm Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
DaleHohm Posted March 16, 2007 Share Posted March 16, 2007 Yikes... this appears to be much harder than you would expect it to be. Google RTFBody and you'll find a lot of discussion... essentually it requires that you need to create an RTF text stream instead of "including" a document. Looks like HTMLBody format is much easier to deal with and should give you the same rich formatting... you can convert a word doc to html... Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
Moderators big_daddy Posted March 16, 2007 Moderators Share Posted March 16, 2007 Sorry it took me so long, but this works for me. expandcollapse popup#include <IE.au3> #include <Word.au3> Const $olMailItem = 0 Const $olByValue = 1 Const $olByReference = 4 Const $olEmbeddeditem = 5 Const $olOLE = 6 _WordErrorHandlerRegister () $sFilePath = @ScriptDir & "\test.doc" $oWordApp = _WordCreate ($sFilePath, 1, 0) $oDoc = _WordDocGetCollection ($oWordApp, 0) $sDoc = $oDoc.Range.Text _WordQuit ($oWordApp) $oOutlook = ObjCreate("Outlook.Application") $sSubject = "Email Subject" $sTo = "someone@somewhere.com" $sAttachment = @ScriptDir & "\test.txt" _SendEmailItem($oOutlook, $sSubject, $sTo, $sDoc, $sAttachment) Func _SendEmailItem($o_Object, $s_SubjectEmail, $s_ToEmail, $s_BodyEmail, $s_Attachment = "") Local $o_EMail = $o_Object.CreateItem ($olMailItem) With $o_EMail .To = $s_ToEmail .Subject = $s_SubjectEmail .Body = $s_BodyEmail If $s_Attachment <> "" Then .Attachments.Add ($s_Attachment, $olByValue, 0) EndIf .Send () EndWith EndFunc ;==>_SendEmailItem Link to comment Share on other sites More sharing options...
DaleHohm Posted March 16, 2007 Share Posted March 16, 2007 (edited) Yikes... this appears to be much harder than you would expect it to be. Google RTFBody and you'll find a lot of discussion... essentually it requires that you need to create an RTF text stream instead of "including" a document.Looks like HTMLBody format is much easier to deal with and should give you the same rich formatting... you can convert a word doc to html...DaleIt appears taht the "Redemption" library may give you more to work with. I had only been aware of its use related to the Outlook Security patch issues, but it appears to allow more: "Directly access RTF body of any Outlook item". You'll find it (free) here: http://www.dimastr.com/redemption/home.htmDaleEdit: small typo Edited March 16, 2007 by DaleHohm Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
DaleHohm Posted March 16, 2007 Share Posted March 16, 2007 And more info here: How to create formatted messages in Microsoft Outlook - http://www.outlookcode.com/d/formatmsg.htmDale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
DaleHohm Posted March 16, 2007 Share Posted March 16, 2007 So I'm doing this research and didn't notice that Bob slipped a working example into the thread... please backup and see post 7 above Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
taurus905 Posted March 18, 2007 Author Share Posted March 18, 2007 DaleHolm and big_daddy, Thank you both for your input. Your ideas helped me to complete my script. I ended up doing the following to paste the contents of a word document: $oWord = ObjCreate("Word.Application") $oWord.Documents.Open($Body_Path) With $oWord.Activewindow.Selection .WholeStory .Copy EndWith $oWord.Quit; Close the Word object. $oWord = ""; Nullify the object string just to clean things up. $oMail.Display Send("^v") (Note that I did not need the rich text formatting.) And I used this to add the attachment: $oMail.Attachments.Add($Attach_Path) Thanks again for taking enough interest in my question to spend your time to research and respond to this post. taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs 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