Outlook 2003 - Turn Word on or off as e-mail editor or viewer

T

thomas

Hello,

With an Excel 2003 VBA procedure I send e-mails through Outlook 2003

Whenever the option of Outlook 2003 "Use Microsoft Word to edit e-mail
messages" is checked my mail i made with a blank body.

How can i uncheck the option using VBA and then restore it to its previous
state at the end of the procedure?

Same question for the second option "Use Microsoft Word to read e-mail
messages with rtf format"

Many thanks
 
K

Ken Slovak - [MVP - Outlook]

You can't. Outlook reads the settings from the registry and then persists
them in memory. When you change the settings the new settings are written
out to the registry but not read again until Outlook closes and is
restarted. So any change you make there when Outlook is running already is
ignored while Outlook is running.

The answer is to correctly handle WordMail when it is being used. You can
always use the Body or HTMLBody properties whether or not WordMail is being
used. I don't know what your code is doing but I often modify Body or
HTMLBody irregardless if WordMail is being used.
 
T

thomas

Thanks,

Hereunder my code. It always works fine excepted when the word option is
checked

In such a cas i only get the signature


Private Function EnvoiMail_HTML(Adresse As String, Objet As String, Corps As
String, Optional Pièce As String, Optional Cc As String, Optional Bcc As
String, Optional Envoyer_Mail As Boolean)

Dim MonAppliOutlook As Outlook.Application
Dim MonMail As Outlook.MailItem
Dim MaPièce As Outlook.Attachments
Dim olInspector As Outlook.Inspector

Set MonAppliOutlook = CreateObject("Outlook.Application")
Set MonMail = MonAppliOutlook.CreateItem(olMailItem)
Set olInspector = MonMail.GetInspector

On Error Resume Next
With MonMail
If Affichage = True Then .Display Else
..GetInspector.CommandBars.Item("Insert").Controls("Signature").Controls(1).Execute
.To = Adresse
If Not IsNull(Cc) Then .Cc = Cc
If Not IsNull(Bcc) Then .Bcc = Bcc
.Subject = Objet
If Not IsNull(Pièce) Then
Set MaPièce = .Attachments
T = Split(Pièce, ";")
For i = 0 To UBound(T)
MaPièce.Add T(i), olByValue
Next i
End If
.BodyFormat = olFormatHTML
.HTMLBody = Corps & .HTMLBody
If Envoyer_Mail = True Then .Send
End With

Set MonAppliOutlook = Nothing
Set MonMail = Nothing


End Function

"Ken Slovak - [MVP - Outlook]" <[email protected]> a écrit dans le message
de groupe de discussion : #[email protected]...
You can't. Outlook reads the settings from the registry and then persists
them in memory. When you change the settings the new settings are written
out to the registry but not read again until Outlook closes and is
restarted. So any change you make there when Outlook is running already is
ignored while Outlook is running.

The answer is to correctly handle WordMail when it is being used. You can
always use the Body or HTMLBody properties whether or not WordMail is being
used. I don't know what your code is doing but I often modify Body or
HTMLBody irregardless if WordMail is being used.
 
K

Ken Slovak - [MVP - Outlook]

WordMail is less forgiving of HTML problems than the Outlook editor is. You
really should get the HTMLBody and then parse that string looking for the
<body> tag and then insert your formatted HTML text into the HTMLBody string
in the correct location. Then set HTMLBody back to your modified string
value.

Also, in WordMail that menu command isn't there, so your code should test
for Inspector.IsWordMail before calling that menu command. If signatures
have been set up they will be added automatically by WordMail.

You can also use Inspector.WordEditor when it's WordMail to get WordEditor,
which is a Word.Document object. You can then manipulate the text that way.

WordMail signatures are inserted by using AutoText entries in the WordMail
template, not from the Insert menu.
 
T

thomas

Thnaks but i am afraid i do not understand


"Ken Slovak - [MVP - Outlook]" <[email protected]> a écrit dans le message
de groupe de discussion : (e-mail address removed)...
WordMail is less forgiving of HTML problems than the Outlook editor is. You
really should get the HTMLBody and then parse that string looking for the
<body> tag and then insert your formatted HTML text into the HTMLBody string
in the correct location. Then set HTMLBody back to your modified string
value.

Also, in WordMail that menu command isn't there, so your code should test
for Inspector.IsWordMail before calling that menu command. If signatures
have been set up they will be added automatically by WordMail.

You can also use Inspector.WordEditor when it's WordMail to get WordEditor,
which is a Word.Document object. You can then manipulate the text that way.

WordMail signatures are inserted by using AutoText entries in the WordMail
template, not from the Insert menu.
 
K

Ken Slovak - [MVP - Outlook]

What don't you understand? Please be specific, I can't just guess.
 
T

thomas

I just understand nothing


"Ken Slovak - [MVP - Outlook]" <[email protected]> a écrit dans le message
de groupe de discussion : (e-mail address removed)...
What don't you understand? Please be specific, I can't just guess.
 
K

Ken Slovak - [MVP - Outlook]

1. You are just adding your own HTML to the beginning of the existing HTML.
You need to look at the original HTML and what you end up with after you add
your HTML to see if it's valid HTML syntax.

2. The menu option you are using to insert the signature isn't there in
WordMail. So you have to check for WordMail being used. If it is you should
avoid that code. Any automatic signatures will be added by WordMail on its
own. If you want to add a signature yourself when it's WordMail you have to
do it in pure HTML or have that signature set as an AutoText entry and use
Word code to insert that AutoText entry.

3. If you get Inspector.WordEditor when WordMail is being used that is a
Word.Document object. So you can change the text that's there using the Word
object model if you want once you get that Document object.

That's about as simple as I can make it.
 
T

thomas

Thanks but how can i check with VBA if WordMail is being used or not ?

i should write something like :
if {wordmail is not being used} then Set olInspector =
MonMail.GetInspector

?



"Ken Slovak - [MVP - Outlook]" <[email protected]> a écrit dans le message
de groupe de discussion : (e-mail address removed)...
1. You are just adding your own HTML to the beginning of the existing HTML.
You need to look at the original HTML and what you end up with after you add
your HTML to see if it's valid HTML syntax.

2. The menu option you are using to insert the signature isn't there in
WordMail. So you have to check for WordMail being used. If it is you should
avoid that code. Any automatic signatures will be added by WordMail on its
own. If you want to add a signature yourself when it's WordMail you have to
do it in pure HTML or have that signature set as an AutoText entry and use
Word code to insert that AutoText entry.

3. If you get Inspector.WordEditor when WordMail is being used that is a
Word.Document object. So you can change the text that's there using the Word
object model if you want once you get that Document object.

That's about as simple as I can make it.
 
K

Ken Slovak - [MVP - Outlook]

Dim oInspector As Outlook.Inspector
Set oInspector = MonMail.GetInspector
If oInspector.IsWordMail Then
' is WordMail
Else
' no WordMail
End If
 
T

thomas

Thanks but i get a 424 error on "If oInspector.IsWordMail Then"



"Ken Slovak - [MVP - Outlook]" <[email protected]> a écrit dans le message
de groupe de discussion : #[email protected]...
Dim oInspector As Outlook.Inspector
Set oInspector = MonMail.GetInspector
If oInspector.IsWordMail Then
' is WordMail
Else
' no WordMail
End If
 
K

Ken Slovak - [MVP - Outlook]

That's the "object required" error and usually it occurs if one or more of
your objects is not instantiated. Are you setting MonMail before using it to
get an Inspector? Is it a valid object at that time? Is oInspector valid?
Run in debug mode, stepping your code on those lines, and check in each case
that the object on that line is not Nothing.
 
T

thomas

My code is :


Private Function EnvoiMail_HTML(Adresse As String, Objet As String, Corps As
String, Optional Pièce As String, Optional Cc As String, Optional Bcc As
String, Optional Envoyer_Mail As Boolean)

Dim MonAppliOutlook As Outlook.Application
Dim MonMail As Outlook.MailItem
Dim MaPièce As Outlook.Attachments
Dim olInspector As Outlook.Inspector

Set MonAppliOutlook = CreateObject("Outlook.Application")
Set MonMail = MonAppliOutlook.CreateItem(olMailItem)
Set olInspector = MonMail.GetInspector

If oInspector.IsWordMail Then ' The 424 error is here
' is WordMail 'Just for test
Else
' no WordMail 'Just for test
End If


On Error Resume Next
With MonMail
If Affichage = True Then .Display Else
..GetInspector.CommandBars.Item("Insert").Controls("Signature").Controls(1).Execute
.To = Adresse
If Not IsNull(Cc) Then .Cc = Cc
If Not IsNull(Bcc) Then .Bcc = Bcc
.Subject = Objet
If Not IsNull(Pièce) Then
Set MaPièce = .Attachments
T = Split(Pièce, ";")
For i = 0 To UBound(T)
MaPièce.Add T(i), olByValue
Next i
End If
.BodyFormat = olFormatHTML
.HTMLBody = Corps & .HTMLBody
If Envoyer_Mail = True Then .Send
End With

Set MonAppliOutlook = Nothing
Set MonMail = Nothing


End Function




"thomas" <nomail> a écrit dans le message de groupe de discussion :
(e-mail address removed)...
Thanks but i get a 424 error on "If oInspector.IsWordMail Then"



"Ken Slovak - [MVP - Outlook]" <[email protected]> a écrit dans le message
de groupe de discussion : #[email protected]...
Dim oInspector As Outlook.Inspector
Set oInspector = MonMail.GetInspector
If oInspector.IsWordMail Then
' is WordMail
Else
' no WordMail
End If
 
K

Ken Slovak - [MVP - Outlook]

The names of the Inspector variable aren't the same on these lines:

Set olInspector = MonMail.GetInspector

If oInspector.IsWordMail Then ' The 424 error is here

Use the same variable name in both lines.
 
T

thomas

oh thanks

i should have seen it

detection works fine

but what should be the code when oInspector.IsWordMail ? where can i find
examples ?

Thanks


"Ken Slovak - [MVP - Outlook]" <[email protected]> a écrit dans le message
de groupe de discussion : (e-mail address removed)...
The names of the Inspector variable aren't the same on these lines:

Set olInspector = MonMail.GetInspector

If oInspector.IsWordMail Then ' The 424 error is here

Use the same variable name in both lines.
 
T

thomas

I think I found out => .BodyFormat = olFormatPlain instead of .BodyFormat =
olFormatHTML , but since the variable "corps" contains html tags there are
big changes to make and it may not be worth

I think I will just exit the procedure if the editor is mail unless I find a
way to get rid of these tags

I had an other problem : When I send an html mail with my code to someone
that uses word editor, if my mail is transferred or answered, the original
body of my mail is lost

Thanks


"thomas" <nomail> a écrit dans le message de groupe de discussion :
(e-mail address removed)...

oh thanks

i should have seen it

detection works fine

but what should be the code when oInspector.IsWordMail ? where can i find
examples ?

Thanks


"Ken Slovak - [MVP - Outlook]" <[email protected]> a écrit dans le message
de groupe de discussion : (e-mail address removed)...
The names of the Inspector variable aren't the same on these lines:

Set olInspector = MonMail.GetInspector

If oInspector.IsWordMail Then ' The 424 error is here

Use the same variable name in both lines.
 
K

Ken Slovak - [MVP - Outlook]

That would depend on what actions you want to take based on WordMail or not.
That's up to you.
 
K

Ken Slovak - [MVP - Outlook]

If you send an HTML email and add your text correctly, using correct HTML
syntax, what you send will be preserved. If you add your text to the
existing HTML that will be preserved. If you just replace what exists then
the original is gone. Outlook and WordMail may re-write your HTML to suit
themselves, but the context of what you provide is kept as long as what you
do is syntactically correct.
 
T

thomas

but in which way my html could not be syntactically correct?

i just pick up the different sentences in excel cells then use <p>... </p>
for each sentence, i concatenate them with "&"
that gives

<font face='Arial' size=-1><p>blabla ,</p><p>blabla.</p><p>blabla
..</p></font>

what did i do wrong? Do i need to ad head and body tags ?

thanks

"Ken Slovak - [MVP - Outlook]" <[email protected]> a écrit dans le message
de groupe de discussion : (e-mail address removed)...
If you send an HTML email and add your text correctly, using correct HTML
syntax, what you send will be preserved. If you add your text to the
existing HTML that will be preserved. If you just replace what exists then
the original is gone. Outlook and WordMail may re-write your HTML to suit
themselves, but the context of what you provide is kept as long as what you
do is syntactically correct.
 
K

Ken Slovak - [MVP - Outlook]

You certainly need those tags and possibly others. You will have to analyze
the HTML you create against known good HTML to see what else you might need.
 

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