Macro insert text - HTML converted to rubbish

H

Heather

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.
 
S

Sue Mosher [MVP]

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.
--
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
 
H

Heather

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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top