Switch Mail format

  • Thread starter Thread starter Mats Samson
  • Start date Start date
M

Mats Samson

Can anyone provide me with code for switching/toggle new emails from HTML
to Plain text? The faxserver use we can only have plain text messages.
For normal emails, we use HTML so I need to toggle back afterwards.
Thx for help
Mats
 
When the item opens you can set its BodyFormat property. You would set that
to OlBodyFormat.olFormatPlain.
 
Thanks Ken,
but I'm fairly unfamiliar with Outlook programming, usually I work with
Excel and I know there are special arguments etc that have to be set before
Outlook cooperates with you, so..... I would appreciate if you can give me a
code example?
Cheers
Mats
 
You will obviously need a reference to Outlook in your VBA project. Then in
a code module something like this:

' Module level code
Dim WithEvents colInsp As Outlook.Inspectors
Dim WithEvents oInsp As Outlook.Inspector
Dim oApp As Outlook.Application
Dim oNS As Outlook.NameSpace

Dim blnFirstActivate As Boolean

Sub SetThingsUp()
Set oApp = CreateObject("Outlook.Application")
Set oNS = oApp.GetNameSpace("MAPI")
oNS.Logon "", "", False, False
Set colInsp = oApp.Inspectors
End Sub

Sub colInsp_NewInspector(Inspector As Inspector)
If (Inspector.CurrentItem.Class = olMail) Then
blnFirstActivate = False
Set oInsp = Inspector
End If
End Sub

Sub oInsp.Activate()
If (Not blnFirstActivate) Then
blnFirstActivate = True

If (oInsp.CurrentItem.BodyFormat = olFormatHTML) Then
oInsp.CurrentItem.BodyFormat = olFormatPlain
End If
End If
End Sub
 
Ken,
I find the code confusing!
The WithEvents doesn't fit in to a Module, they seem to fit into a
ThisOutlookSession!?! If I run it from there I get compile error in the "Sub
colInsp_NewInspector(Inspector As Inspector), not matching description or
having the same name.
Furthermore the Sub oInsp.Activate() must be oInsp_Activate, right?

The best solution would be if I can attach the code to a toolbar button so
when I want to send a fax, I press the button and I get a new plain text
message.
Regards
Mats
 
My error there in the instructions, the WithEvents declarations and event
handlers should be in a class (which could be ThisOutlookSession), and yes
the Activate() event should be as you mention for an event signature.

If you want this to run on demand the macro can be much simpler and would be
in either a code module or ThisOutlookSession:

Sub ChangeFormat()
Application.ActiveInspector.CurrentItem.BodyFormat = olFormatPlain
End Sub

However, you can just use the format changing menu commands in that case and
not bother with a macro.
 
Thank you Ken,
your last proposal was in fact the simplest solution, I had overlooked
the toolbar option to switch between different formats AFTER starting
a new mail. I thought it had to be done prior pushing the New button.
Thanks anyway for assistance!
Mats
 
Back
Top