| Code level: advanced Code area: Outlook Expert Techniques Printer Friendly Version | ||
| Title: Add text to plain text message | ||
| Description: In versions of Outlook prior to 2002, it's not possible to use Outlook objects to create a plain text message or to add to a plain text message without changing the format. This Outlook VBA sample shows the basics of using CDO to work with an existing message, presumably in the Drafts folder. It requires a reference in your project to the Microsoft CDO 1.21 library. | ||
| Date: 21-Jul-2003 11:13 | ||
| Code level: advanced | ||
| Code area: Outlook Expert Techniques | ||
| Posted by: Sue Mosher | ||
| Body: |
||
| All 12comments |
| Page [ 1 2 Next >> ] | ||
|
|
Sue Mosher
21-Jul-2003 18:20
Outlook does some caching, so the appended text might not be immediately apparent when you open the item to send it. A possible enhancement, therefore, would be to send the message with CDO (or better yet, use Redemption instead of CDO to avoid security prompts). Because of the caching, changing the text in an item that's open in an Inspector window may not work at all. A possible workaround in that case might be to create a copy of the message, save it, pass it to CDO, modify it, then delete the original. Note the need to delete a couple of MAPI properties to get the text change to show -- a little MAPI voodoo that Outlook Spy (http://www.dimastr.com) is essential for experimenting with. I'm saving the item (.Update) after each change for good measure, but that might be overkill. |
|
|
|
Chris
25-May-2006 15:25
I tried using this code but received an error on the line "Set objField = objMsg.Fields(CdoPR_RTF_SYNC_BODY_COUNT)" of "mapi_e_not_found(800401f)". I have managed to establish that this has something to do with the code not being able to find the message or that it is missing. The code picks up the subject of the selected message in the "objMail" variable. Any thoughts? Taking what this code should do a little further what I want to try and achieve is the ability to add a hyperlink (to a file or dir) into an email. I have figured out how to select the path for the file or dir but am now looking into how I can name the link and insert it in the email with the path of the file or dir. If this is not possible than I'd appreciate knowing that. Thanks. |
|
|
|
Sue Mosher
25-May-2006 16:07
Chris, try uncommenting the On Error Resume Next statement. What version of Outlook are you using? |
|
|
|
Chris
25-May-2006 17:13
Sue, OK, that avoids that error but I cant see the text "Some text added at " being added, although after your suggestion I looked at the test email I was using and the string was in it! Not sure when that was placed there but I cant replicate it. Just so I am using it right. I have saved an email in drafts which has text in the subject and body. I select it (single click) and run the macro "TestAppendText" and it runs through and "objMail" picks up the subject value but noting changes in the email? Am using Outlook 2003 with SP3. |
|
|
|
Sue Mosher
25-May-2006 21:33
Did you create the message in Drafts in plain text format? If you are using Outlook 2003, why are you using this approach, which is intended as a workaround for Outlook 2000 and earlier? |
|
|
|
Chris
28-May-2006 23:20
Yes, I have just tried that and no go. Perhaps I am barking up the wrong tree using this code going by what I am trying to achieve (Post 25May). Thanks for the feedback and I'll continue playing... |
|
|
|
Sue Mosher
31-May-2006 13:48
Chris, still looking for an answer to my last question. |
|
|
|
ali
19-Aug-2008 02:25
do I have a chance to cpoy and paste the test in the message via outlook macro |
|
|
|
Sue Mosher
19-Aug-2008 09:15
ali, if Word is the email editor, you can return a Word.Document object from Inspector.WordEditor and then use Word's methods for copy and pate. Otherwise, you would be limited to executing the controls on the toolbar or menu; see http://wwww.outlookcode.com/d/tips/commandbarfun.htm |
|
|
|
ali
21-Aug-2008 04:41
no I just wanna to use outlook and would like establish a macro which is works very well by excel. this macro is used for copiing ans pasting of marked text areas. it means I need a macro, which allows to me to copy a marked area for using the copied text for another application. |
|
| Page [ 1 2 Next >> ] | ||
| Post your comment name email |
