need Outlook 2002 macro to change mail format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to create a macro in Outlook 2002 to change the mail format from HTML
to rich text and another to change it back to HTML. Can anyone help?
 
Hi Maureen. If you're dealing with these settings at a program level, see my
post here:

Outlook's Message Format Settings In The Registry:
http://blogs.officezealot.com/legault/archive/2004/08/03/1324.aspx

For a specific message, you will have to automate clicking the choices under
the Format menu by using CommandBar and CommandBarButton objects from the
Office Object Model. However, you have to switch to Plain Text in between.
So HTML -> Plain Text -> Rich Text -> Plain Text -> HTML. Why do you need to
do this?
 
I was asked to create a series of documents in Word that includes data pasted
from the clipboard when the Word macro is run. To satisfy all the
requirements, I changed the Outlook mail format to HTML using MS Word to Edit
Email Msgs. We receive some email that takes FOREVER to open in Word when
forwarded (daily procedure), so we need to be able to easily uncheck the MS
Word to Edit Email Msgs box before forwarding these messages and easily
re-check that box. They are used to having buttons on the toolbar to perform
macros and other tasks, so that's why I need a macro in Outlook. I know how
to create a macro in Word and can fake my way through some VBA, but I don't
know where to start to have an Outlook macro change the mailformat for me.
 
If you're new to Outlook VBA, this is an excellent resource to help get you
started:

Visual Basic and VBA Coding in Microsoft Outlook:
http://www.outlookcode.com/d/vb.htm

However, what you want to do doesn't really involve using VBA with the
Outlook Object Model, but direct modifications to the registry as I describe
in my blog post referred to in my previous message. To modify the registry,
Google for "VB Registry Class" for plenty of free source code that can help
you set and retrieve registry values. Once that code is in place inside a
VBA module, wire a macro up to a custom button much like you do in Word.

One caveat: changes to values in registry keys that Outlook uses may not be
read until Outlook is restarted. I currently do not know if Outlook's
message format values in the registry behave in the same way.

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/
 
Am Tue, 14 Mar 2006 10:56:29 -0800 schrieb Eric Legault [MVP - Outlook]:

While with the CommandBar trick you´ll lose all the formattings, in OL 2002
(and up) you could simply switch the Bodyformat property.
 
Maureen said:
I need to create a macro in Outlook 2002 to change the mail format
from HTML
to rich text and another to change it back to HTML. Can anyone
help?


Hi,

The code below will take you from any format (other than already RTF)
to RTF. You should be able to amend to do what you want.

You'll need to amend the folder names too depending on whether the
files and deleted items are in a PST or not.

HTH,

Alan.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Sub Convert_To_RTF()

Dim ConvertItem As MailItem
Dim OriginalItem As MailItem
Dim FolderCollection As Folders
Dim AlanMainMailFileFolders As Folders



Set FolderCollection = Application.GetNamespace("MAPI").Folders
Set AlanMainMailFileFolders = FolderCollection("Alan - Main Mail
File").Folders


' Max items found by trial and error to be greater than 238
' Not sure how many it could handle in one go, but I put in 200 to
play it safe
' Probably related to your PC too?

If ActiveExplorer.Selection.Count > 200 Then

MsgBox "Too many items to do them all at once. Please select
fewer items."

Exit Sub

End If


On Error Resume Next


For Each ConvertItem In ActiveExplorer.Selection

' Check if an OlMail item class and not already RTF

If ((ConvertItem.Class = 43) And Not
(ConvertItem.GetInspector.EditorType = olEditorWord)) Then

Set OriginalItem = ConvertItem.Copy
OriginalItem.Move AlanMainMailFileFolders("Deleted Items")

ConvertItem.Body = ConvertItem.Body & " "

ConvertItem.Save

End If

Next


On Error GoTo 0


MsgBox "Finished converting " & ActiveExplorer.Selection.Count & "
MailItems to RTF"

End Sub


+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

--

The views expressed are my own, and not those of my employer or anyone
else associated with me.

My current valid email address is:

(e-mail address removed)

This is valid as is. It is not munged, or altered at all.

It will be valid for AT LEAST one month from the date of this post.

If you are trying to contact me after that time,
it MAY still be valid, but may also have been
deactivated due to spam. If so, and you want
to contact me by email, try searching for a
more recent post by me to find my current
email address.

The following is a (probably!) totally unique
and meaningless string of characters that you
can use to find posts by me in a search engine:

ewygchvboocno43vb674b6nq46tvb
 
Do you mean that when I open a message, there's a way to change the body
format before clicking on forward? I looked through all the toolbars and
didn't find that choice.
--
Maureen


Michael Bauer said:
Am Tue, 14 Mar 2006 10:56:29 -0800 schrieb Eric Legault [MVP - Outlook]:

While with the CommandBar trick you´ll lose all the formattings, in OL 2002
(and up) you could simply switch the Bodyformat property.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.vbOffice.net --

Hi Maureen. If you're dealing with these settings at a program level, see my
post here:

Outlook's Message Format Settings In The Registry:
http://blogs.officezealot.com/legault/archive/2004/08/03/1324.aspx

For a specific message, you will have to automate clicking the choices under
the Format menu by using CommandBar and CommandBarButton objects from the
Office Object Model. However, you have to switch to Plain Text in between.
So HTML -> Plain Text -> Rich Text -> Plain Text -> HTML. Why do you need to
do this?
 
Thank you for your help, but I'm trying to NOT make any changes in the
registry if possible. Your suggestions have definitely educated me and
helped me though.
 
Thank you!
--
Maureen


Alan said:
Hi,

The code below will take you from any format (other than already RTF)
to RTF. You should be able to amend to do what you want.

You'll need to amend the folder names too depending on whether the
files and deleted items are in a PST or not.

HTH,

Alan.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Sub Convert_To_RTF()

Dim ConvertItem As MailItem
Dim OriginalItem As MailItem
Dim FolderCollection As Folders
Dim AlanMainMailFileFolders As Folders



Set FolderCollection = Application.GetNamespace("MAPI").Folders
Set AlanMainMailFileFolders = FolderCollection("Alan - Main Mail
File").Folders


' Max items found by trial and error to be greater than 238
' Not sure how many it could handle in one go, but I put in 200 to
play it safe
' Probably related to your PC too?

If ActiveExplorer.Selection.Count > 200 Then

MsgBox "Too many items to do them all at once. Please select
fewer items."

Exit Sub

End If


On Error Resume Next


For Each ConvertItem In ActiveExplorer.Selection

' Check if an OlMail item class and not already RTF

If ((ConvertItem.Class = 43) And Not
(ConvertItem.GetInspector.EditorType = olEditorWord)) Then

Set OriginalItem = ConvertItem.Copy
OriginalItem.Move AlanMainMailFileFolders("Deleted Items")

ConvertItem.Body = ConvertItem.Body & " "

ConvertItem.Save

End If

Next


On Error GoTo 0


MsgBox "Finished converting " & ActiveExplorer.Selection.Count & "
MailItems to RTF"

End Sub


+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

--

The views expressed are my own, and not those of my employer or anyone
else associated with me.

My current valid email address is:

(e-mail address removed)

This is valid as is. It is not munged, or altered at all.

It will be valid for AT LEAST one month from the date of this post.

If you are trying to contact me after that time,
it MAY still be valid, but may also have been
deactivated due to spam. If so, and you want
to contact me by email, try searching for a
more recent post by me to find my current
email address.

The following is a (probably!) totally unique
and meaningless string of characters that you
can use to find posts by me in a search engine:

ewygchvboocno43vb674b6nq46tvb
 
Certainly; this option is already there and if you didn't know about it, you
don't need any code.

With an open message, select the format you want from the Format menu. Note
that Rich Text will not be listed if the current format is HTML, and vice
versa. You need to switch to Plain Text when converting between Rich Text
and HTML back and forth.

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


Maureen said:
Do you mean that when I open a message, there's a way to change the body
format before clicking on forward? I looked through all the toolbars and
didn't find that choice.
--
Maureen


Michael Bauer said:
Am Tue, 14 Mar 2006 10:56:29 -0800 schrieb Eric Legault [MVP - Outlook]:

While with the CommandBar trick you´ll lose all the formattings, in OL 2002
(and up) you could simply switch the Bodyformat property.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.vbOffice.net --

Hi Maureen. If you're dealing with these settings at a program level, see my
post here:

Outlook's Message Format Settings In The Registry:
http://blogs.officezealot.com/legault/archive/2004/08/03/1324.aspx

For a specific message, you will have to automate clicking the choices under
the Format menu by using CommandBar and CommandBarButton objects from the
Office Object Model. However, you have to switch to Plain Text in between.
So HTML -> Plain Text -> Rich Text -> Plain Text -> HTML. Why do you need to
do this?
 
You caught me sleeping Michael! Thanks, I forgot about that.

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


Michael Bauer said:
Am Tue, 14 Mar 2006 10:56:29 -0800 schrieb Eric Legault [MVP - Outlook]:

While with the CommandBar trick you´ll lose all the formattings, in OL 2002
(and up) you could simply switch the Bodyformat property.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.vbOffice.net --

Hi Maureen. If you're dealing with these settings at a program level, see my
post here:

Outlook's Message Format Settings In The Registry:
http://blogs.officezealot.com/legault/archive/2004/08/03/1324.aspx

For a specific message, you will have to automate clicking the choices under
the Format menu by using CommandBar and CommandBarButton objects from the
Office Object Model. However, you have to switch to Plain Text in between.
So HTML -> Plain Text -> Rich Text -> Plain Text -> HTML. Why do you need to
do this?
 
Since the majority of the time we need HTML format and Use Word as Email
Editor, that's the default. When I open a message that I want to forward, I
have no choices available when I click on Format.
--
Maureen


Eric Legault said:
Certainly; this option is already there and if you didn't know about it, you
don't need any code.

With an open message, select the format you want from the Format menu. Note
that Rich Text will not be listed if the current format is HTML, and vice
versa. You need to switch to Plain Text when converting between Rich Text
and HTML back and forth.

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


Maureen said:
Do you mean that when I open a message, there's a way to change the body
format before clicking on forward? I looked through all the toolbars and
didn't find that choice.
--
Maureen


Michael Bauer said:
Am Tue, 14 Mar 2006 10:56:29 -0800 schrieb Eric Legault [MVP - Outlook]:

While with the CommandBar trick you´ll lose all the formattings, in OL 2002
(and up) you could simply switch the Bodyformat property.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.vbOffice.net --


Hi Maureen. If you're dealing with these settings at a program level, see
my
post here:

Outlook's Message Format Settings In The Registry:
http://blogs.officezealot.com/legault/archive/2004/08/03/1324.aspx

For a specific message, you will have to automate clicking the choices
under
the Format menu by using CommandBar and CommandBarButton objects from the
Office Object Model. However, you have to switch to Plain Text in
between.
So HTML -> Plain Text -> Rich Text -> Plain Text -> HTML. Why do you need
to
do this?
 
Am Wed, 15 Mar 2006 08:34:23 -0800 schrieb Eric Legault [MVP - Outlook]:


You caught me sleeping Michael! Thanks, I forgot about that.

Frankly, I never used that method and had to run a little test... :-)
 
Am Wed, 15 Mar 2006 06:45:28 -0800 schrieb Maureen:

No, you first need to click on Forward.

This little sample creates the forward mail and switches the format:

Sub test111()
Dim mail As MailItem
Set mail = Application.ActiveInspector.CurrentItem.Forward
If mail.BodyFormat = olFormatHTML Then
mail.BodyFormat = olFormatRichText
Else
mail.BodyFormat = olFormatHTML
End If
End Sub

You could add your own button to the toolbar and run that code by clicking
the button.
 
When I click on Forward that's when it takes FOREVER for the message to open
in Word. I need to change the format before clicking on Forward.

Maybe I can go at it another way. Do you know of a way to have an Outlook
macro open Word and run a Word macro, then close Word and insert a Word
document in the body of a new message? The Word document has form wording at
the top, then clipboard contents are pasted and formatted in a specific font,
then there is form wording at the bottom along with some links to web sites.
The Word macro that creates this document works great, but our network users
don't use Word and want to click on a button in Outlook that starts a new
message and inserts the result of a Word macro in that message.
 
Maureen said:
Thank you!


You're welcome - glad it worked for you.

Alan.

--

The views expressed are my own, and not those of my employer or anyone
else associated with me.

My current valid email address is:

(e-mail address removed)

This is valid as is. It is not munged, or altered at all.

It will be valid for AT LEAST one month from the date of this post.

If you are trying to contact me after that time,
it MAY still be valid, but may also have been
deactivated due to spam. If so, and you want
to contact me by email, try searching for a
more recent post by me to find my current
email address.

The following is a (probably!) totally unique
and meaningless string of characters that you
can use to find posts by me in a search engine:

ewygchvboocno43vb674b6nq46tvb
 
Am Wed, 15 Mar 2006 11:37:25 -0800 schrieb Maureen:

Maureen, the Word.Application object has a Run function.

You´d need to save the Word Document then as a RTF or HTML file.

If you need it as HTML then simply open the file (e.g. with the
FileSystemObject from the Scripting Runtime Library) read it and insert the
string into the e-mail´s HTMLBody property.

For RTF it´s more work. For inserting that into the e-mail I´d recommend you
the Redemption from www.dimastr.com
 
Back
Top