Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / September 2003

Tip: Looking for answers? Try searching our database.

Macro insert text - HTML converted to rubbish

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Heather - 04 Sep 2003 16:49 GMT
Outlook 2002

I receive messages that are 'undeliverable'.  I read the message and
before I re-send it, I would like to run a macro to insert text at the
beginning of the message.

This works perfectly for incoming Rich Text messages but when I run
the code on HTML messages, the text is inserted but the original
message is converted to strange characters.

I have tried setting my default editor to HTML and Rich text but this
has no effect.

Is it possible to do this?  At present I have to ignore records where
the EditorType is 2.

Any help much appreciated.
Sue Mosher [MVP] - 04 Sep 2003 17:13 GMT
A code snippet might be illustrative.

If you're working with an HTML-format message, you should be setting HTMLBody and using fully tagged HTML text.
Signature

Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
    Microsoft Outlook Programming: Jumpstart
    for Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx 

> Outlook 2002
>
[quoted text clipped - 13 lines]
>
> Any help much appreciated.
Heather - 29 Sep 2003 17:54 GMT
> Outlook 2002
>
[quoted text clipped - 13 lines]
>
> Any help much appreciated.

Thanks for your help.

The code below works for rich text but not HTML messages.

Sub InsertSampleText()

'Inserts text into new or forwarded messages

   Dim myolapp As Outlook.Application
   Dim myItem As Object
   Dim myItemEditor As Integer
   Dim sHTML1 As String
   Dim sHTML2 As String
       
   On Error GoTo Abort
   
   Set myolapp = CreateObject("Outlook.Application")
   Set myItem = myolapp.ActiveInspector.CurrentItem
   
   'Test message class - 46=Undeliverable
   
   If myItem.Class = 46 Then
   
       If myolapp.ActiveInspector.EditorType = olEditorHTML Then
           sHTML1 = "<html><head><body>"
           sHTML2 = "</body></html>"
           myItem.HTMLBody = sHTML1 & "This message has been
quarantined or mis-addressed " & _
               "and has been forwarded to you as the intended
recipient." _
               & vbCrLf & vbCrLf & myItem.HTMLBody & sHTML2
               
       Else
          myItem.Body = "This message has been quarantined or
mis-addressed " & _
               "and has been forwarded to you as the intended
recipient." _
               & vbCrLf & vbCrLf & myItem.Body

       End If
   End If
   
Abort:

End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.