VBA toggle Outlook '03 Word email editor on/off

J

J Smith 555

Hello,

This is a follow-up post to what I have posted on another forum (please see:
http://www.microsoft.com/communitie...ming&mid=5c23ec0c-60ed-4b43-9302-81c2d86f3a13
); I was wondering if anyone here might have come across a similar question.
I have thumbed through the threads that I thought were relevant and have
tried a few variations but without any success.

What I am attempting to do is confirm through VBA whether or not someone has
the ‘Use Microsoft Office Word 2003 to edit e-mail messages’ option selected
from their Outlook 2003 profile. The script that Ron devolved has a caveat
where the ‘RangeToHTML’ function (see
http://www.rondebruin.nl/mail/folder3/mail4.htm for detail) will not work if
that option is selected. If the person has that option ‘active’ have the
script turn it off .. if they don’t then the script will run as normal. Then
at the end put it back the way their options were of course; assuming since
it’s a script it won’t actually ‘change’ the end users Outlook settings.

My problem stems from not understanding how to call ‘IsWordEditor’ module /
class / etc correctly from Excel’s VBA GUI.

Thank you in advance for your help,

J
 
E

Eric Legault [MVP - Outlook]

You can check if Inspector.WordEditor is a null object. That property
equates to the Document object in Word.

You can also check and change these settings in the registry:

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

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007
& WSS 3.0 Application Development)
President
Collaborative Innovations
-> Try Picture Attachments Wizard 2.0 For Microsoft Outlook <-
-> Take your SharePoint content offline <-
-> More info: http://www.collaborativeinnovations.ca <-
Blog: http://blogs.officezealot.com/legault
 
J

J Smith 555

Eric,

Thank you for your quick reply, I have included a copy of the code I am
working with so I can detail what error(s) I am getting. I am using Excel
2003 with Outlook 2003 running on XP Pro SP2 (please see below)

This is the problem I am running into, I am unable to call the
'Inspector.WordEditor' correctly,
- If I 'Set TestOutlookEditor = ActiveInspector("Outlook.Application")' and
I go to 'Debug >> Compile VBAProject'. I get error msg 'Compile error: Sub or
Function not defined' .. the debug highlights the word 'ActiveInsepctor'

- if I 'Set TestEditor = Inspector.WordEditor("Word.Application")' I get
error msg 'Run-time errror '424': Object required' .. if I 'MouseOver' the
word 'TestEditor' the debug says 'TestEditor = Empty'

My theory is this: if I can confirm that the end user (person running
script) has their's set to 'True' then I can get the script to work then
Ron's email script will work correctly, if the user has it set to 'False'
then the script will run without any troubles.

Sorry for not clarifing earlier.

Sub TestHTMLEmailEditor_MSDN()

'************ Test Code
' This creates an email with a preset list of people who request the data.

Dim TestHTMLString As String

Set OutlookApp = CreateObject("Outlook.Application")
Set MItem = OutlookApp.CreateItem(olMailItem)

' ****Test variable(s) to check Outlook msg formatting .. currently not
working
'Set TestOutlookEditor = ActiveInspector("Outlook.Application") 'set option
not working .. commenting out
Set TestEditor = Inspector.WordEditor("Word.Application")

' Below is the section of code I am unable to get to work
' **********************
If TestEditor.Inspector.WordEditor = Null Then
MsgBox ("Pass") ' confirmation from Excel if value is true
Else
MsgBox ("Failed") ' confirmation from Excel if value is False
End If
' ********************** End of test code

TestHTMLString = "<font face=Arial><font size=2><color=#000000>Hello
Everyone,<br /><br />" & _
"<span style=background-color:#FF0000><font
color=#FFFFFF>Red</span>" & _
"<font color=#4B0082> = Hello new line.<br /> " & _
"<font color=#FF00FF>Testing<br />" & _
"<font color=#000000><dir>" & _
"<li>Line <b>2</b></dir><br />" & _
"Testing new line"

With MItem
.To = ""
.CC = ""
.Subject = "Test Email using HTML on " & Format(Now, "dddd mm/dd/yy")
.htmlBody = TestHTMLString
.Display ' This allows the email to show vs auto
sending
End With

Set OutlookApp = Nothing
Set MItem = Nothing

End Sub


Eric Legault said:
You can check if Inspector.WordEditor is a null object. That property
equates to the Document object in Word.

You can also check and change these settings in the registry:

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

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007
& WSS 3.0 Application Development)
President
Collaborative Innovations
-> Try Picture Attachments Wizard 2.0 For Microsoft Outlook <-
-> Take your SharePoint content offline <-
-> More info: http://www.collaborativeinnovations.ca <-
Blog: http://blogs.officezealot.com/legault


J Smith 555 said:
Hello,

This is a follow-up post to what I have posted on another forum (please
see:
http://www.microsoft.com/communitie...ming&mid=5c23ec0c-60ed-4b43-9302-81c2d86f3a13
); I was wondering if anyone here might have come across a similar
question.
I have thumbed through the threads that I thought were relevant and have
tried a few variations but without any success.

What I am attempting to do is confirm through VBA whether or not someone
has
the ‘Use Microsoft Office Word 2003 to edit e-mail messages’ option
selected
from their Outlook 2003 profile. The script that Ron devolved has a caveat
where the ‘RangeToHTML’ function (see
http://www.rondebruin.nl/mail/folder3/mail4.htm for detail) will not work
if
that option is selected. If the person has that option ‘active’ have the
script turn it off .. if they don’t then the script will run as normal.
Then
at the end put it back the way their options were of course; assuming
since
it’s a script it won’t actually ‘change’ the end users Outlook settings.

My problem stems from not understanding how to call ‘IsWordEditor’ module
/
class / etc correctly from Excel’s VBA GUI.

Thank you in advance for your help,

J
 
J

J Smith 555

Eric,

I implemented the code you suggested into my procedure and I am able to
'debug >> Compile VBAProject' without any troubles errors. What I am running
into is that when I step through the code (regardless if I have Word 2003 as
my email editor selected or not) 'objWordDoc' always returns 'objWordDoc =
nothing' .. I have included my updated code (shortened slightly for space
reasons) so you see what I see.

Thank you agian for your time,

Sub TestHTMLEmailEditor_MSDN()

Set OutlookApp = CreateObject("Outlook.Application")
Set MItem = OutlookApp.CreateItem(olMailItem)

Dim TestHTMLString As String

Dim objWordDoc As Word.Document
Set objWordDoc = ActiveInspector.WordEditor

If objWordDoc Is Nothing Then
MsgBox ("Word 2003 is NOT selected")
Else
MsgBox ("Word 2003 is the active email editor") 'This is Word Mail!
End If

TestHTMLString = "<font face=Arial><font size=2><color=#000000>Hello
Everyone,<br /><br />" & _
"<span style=background-color:#FF0000><font
color=#FFFFFF>Red</span><br />" & _
"<font color=#FFFFFF>Testing new line"

With MItem
.To = ""
.htmlBody = TestHTMLString
.Display ' This allows the email to show vs auto
sending
End With

Set OutlookApp = Nothing
Set MItem = Nothing
Set objWordDoc = Nothing

End Sub

Eric Legault said:
This is how you should be testing:

Dim objWordDoc As Word.Document 'Make sure you have a reference set to the
Microsoft Word 2003 Object Model

Set objWordDoc = ActiveInspector.WordEditor

If objWordDoc Is Nothing Then
'This isn't Word Mail
Else
'This is Word Mail!
End If

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007
& WSS 3.0 Application Development)
President
Collaborative Innovations
-> Try Picture Attachments Wizard 2.0 For Microsoft Outlook <-
-> Take your SharePoint content offline <-
-> More info: http://www.collaborativeinnovations.ca <-
Blog: http://blogs.officezealot.com/legault


J Smith 555 said:
Eric,

Thank you for your quick reply, I have included a copy of the code I am
working with so I can detail what error(s) I am getting. I am using Excel
2003 with Outlook 2003 running on XP Pro SP2 (please see below)

This is the problem I am running into, I am unable to call the
'Inspector.WordEditor' correctly,
- If I 'Set TestOutlookEditor = ActiveInspector("Outlook.Application")'
and
I go to 'Debug >> Compile VBAProject'. I get error msg 'Compile error: Sub
or
Function not defined' .. the debug highlights the word 'ActiveInsepctor'

- if I 'Set TestEditor = Inspector.WordEditor("Word.Application")' I get
error msg 'Run-time errror '424': Object required' .. if I 'MouseOver' the
word 'TestEditor' the debug says 'TestEditor = Empty'

My theory is this: if I can confirm that the end user (person running
script) has their's set to 'True' then I can get the script to work then
Ron's email script will work correctly, if the user has it set to 'False'
then the script will run without any troubles.

Sorry for not clarifing earlier.

Sub TestHTMLEmailEditor_MSDN()

'************ Test Code
' This creates an email with a preset list of people who request the data.

Dim TestHTMLString As String

Set OutlookApp = CreateObject("Outlook.Application")
Set MItem = OutlookApp.CreateItem(olMailItem)

' ****Test variable(s) to check Outlook msg formatting .. currently not
working
'Set TestOutlookEditor = ActiveInspector("Outlook.Application") 'set
option
not working .. commenting out
Set TestEditor = Inspector.WordEditor("Word.Application")

' Below is the section of code I am unable to get to work
' **********************
If TestEditor.Inspector.WordEditor = Null Then
MsgBox ("Pass") ' confirmation from Excel if value is true
Else
MsgBox ("Failed") ' confirmation from Excel if value is False
End If
' ********************** End of test code

TestHTMLString = "<font face=Arial><font size=2><color=#000000>Hello
Everyone,<br /><br />" & _
"<span style=background-color:#FF0000><font
color=#FFFFFF>Red</span>" & _
"<font color=#4B0082> = Hello new line.<br /> " & _
"<font color=#FF00FF>Testing<br />" & _
"<font color=#000000><dir>" & _
"<li>Line <b>2</b></dir><br />" & _
"Testing new line"

With MItem
.To = ""
.CC = ""
.Subject = "Test Email using HTML on " & Format(Now, "dddd
mm/dd/yy")
.htmlBody = TestHTMLString
.Display ' This allows the email to show vs auto
sending
End With

Set OutlookApp = Nothing
Set MItem = Nothing

End Sub


Eric Legault said:
You can check if Inspector.WordEditor is a null object. That property
equates to the Document object in Word.

You can also check and change these settings in the registry:

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

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS
2007
& WSS 3.0 Application Development)
President
Collaborative Innovations
-> Try Picture Attachments Wizard 2.0 For Microsoft Outlook <-
-> Take your SharePoint content offline <-
-> More info: http://www.collaborativeinnovations.ca <-
Blog: http://blogs.officezealot.com/legault


Hello,

This is a follow-up post to what I have posted on another forum (please
see:
http://www.microsoft.com/communitie...ming&mid=5c23ec0c-60ed-4b43-9302-81c2d86f3a13
); I was wondering if anyone here might have come across a similar
question.
I have thumbed through the threads that I thought were relevant and
have
tried a few variations but without any success.

What I am attempting to do is confirm through VBA whether or not
someone
has
the ‘Use Microsoft Office Word 2003 to edit e-mail messages’ option
selected
from their Outlook 2003 profile. The script that Ron devolved has a
caveat
where the ‘RangeToHTML’ function (see
http://www.rondebruin.nl/mail/folder3/mail4.htm for detail) will not
work
if
that option is selected. If the person has that option ‘active’ have
the
script turn it off .. if they don’t then the script will run as normal.
Then
at the end put it back the way their options were of course; assuming
since
it’s a script it won’t actually ‘change’ the end users Outlook
settings.

My problem stems from not understanding how to call ‘IsWordEditor’
module
/
class / etc correctly from Excel’s VBA GUI.

Thank you in advance for your help,

J
 
J

J Smith 555

Eric,

Sorry for the delay in the response, I have attempted to use the suggestion
you gave to 'produce an active inspector window' using a with statement (see
below).


Set OutlookApp = CreateObject("Outlook.Application")
Set MItem = OutlookApp.CreateItem(olMailItem)
Set TestOutlookEditor = ActiveInspector("Outlook.Application")

With mItem
.display ‘creates a blank email

If TestOutlookEditor.IsWordEditor = True Then
MsgBox ("Pass") ' confirmation from Excel if value is true
Else
MsgBox ("Failed") ' confirmation from Excel if value is False
End If
End with


I hate to say it but, at this point I am a little above my head trying to
figure out the command string needed to get the code to return a 'true /
false' or whatever would be needed so I can toggle the editor on / off.

Please let me know if you have any sample code that can retrieve the editor.

Thank you again for your time,

J

Eric Legault said:
Are you sure you have an e-mail open? The Set MItem =
OutlookApp.CreateItem(olMailItem) call does not produce an active inspector
window until you cal MItem.Display. You don't have error handling turned
off so you *should* get an error with the Set objWordDoc =
ActiveInspector.WordEditor call because ActiveInspector would be Nothing if
there's no open message.

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007
& WSS 3.0 Application Development)
President
Collaborative Innovations
-> Try Picture Attachments Wizard 2.0 For Microsoft Outlook <-
-> Take your SharePoint content offline <-
-> More info: http://www.collaborativeinnovations.ca <-
Blog: http://blogs.officezealot.com/legault


J Smith 555 said:
Eric,

I implemented the code you suggested into my procedure and I am able to
'debug >> Compile VBAProject' without any troubles errors. What I am
running
into is that when I step through the code (regardless if I have Word 2003
as
my email editor selected or not) 'objWordDoc' always returns 'objWordDoc =
nothing' .. I have included my updated code (shortened slightly for space
reasons) so you see what I see.

Thank you agian for your time,

Sub TestHTMLEmailEditor_MSDN()

Set OutlookApp = CreateObject("Outlook.Application")
Set MItem = OutlookApp.CreateItem(olMailItem)

Dim TestHTMLString As String

Dim objWordDoc As Word.Document
Set objWordDoc = ActiveInspector.WordEditor

If objWordDoc Is Nothing Then
MsgBox ("Word 2003 is NOT selected")
Else
MsgBox ("Word 2003 is the active email editor") 'This is Word Mail!
End If

TestHTMLString = "<font face=Arial><font size=2><color=#000000>Hello
Everyone,<br /><br />" & _
"<span style=background-color:#FF0000><font
color=#FFFFFF>Red</span><br />" & _
"<font color=#FFFFFF>Testing new line"

With MItem
.To = ""
.htmlBody = TestHTMLString
.Display ' This allows the email to show vs auto
sending
End With

Set OutlookApp = Nothing
Set MItem = Nothing
Set objWordDoc = Nothing

End Sub

Eric Legault said:
This is how you should be testing:

Dim objWordDoc As Word.Document 'Make sure you have a reference set to
the
Microsoft Word 2003 Object Model

Set objWordDoc = ActiveInspector.WordEditor

If objWordDoc Is Nothing Then
'This isn't Word Mail
Else
'This is Word Mail!
End If

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS
2007
& WSS 3.0 Application Development)
President
Collaborative Innovations
-> Try Picture Attachments Wizard 2.0 For Microsoft Outlook <-
-> Take your SharePoint content offline <-
-> More info: http://www.collaborativeinnovations.ca <-
Blog: http://blogs.officezealot.com/legault


Eric,

Thank you for your quick reply, I have included a copy of the code I am
working with so I can detail what error(s) I am getting. I am using
Excel
2003 with Outlook 2003 running on XP Pro SP2 (please see below)

This is the problem I am running into, I am unable to call the
'Inspector.WordEditor' correctly,
- If I 'Set TestOutlookEditor = ActiveInspector("Outlook.Application")'
and
I go to 'Debug >> Compile VBAProject'. I get error msg 'Compile error:
Sub
or
Function not defined' .. the debug highlights the word
'ActiveInsepctor'

- if I 'Set TestEditor = Inspector.WordEditor("Word.Application")' I
get
error msg 'Run-time errror '424': Object required' .. if I 'MouseOver'
the
word 'TestEditor' the debug says 'TestEditor = Empty'

My theory is this: if I can confirm that the end user (person running
script) has their's set to 'True' then I can get the script to work
then
Ron's email script will work correctly, if the user has it set to
'False'
then the script will run without any troubles.

Sorry for not clarifing earlier.

Sub TestHTMLEmailEditor_MSDN()

'************ Test Code
' This creates an email with a preset list of people who request the
data.

Dim TestHTMLString As String

Set OutlookApp = CreateObject("Outlook.Application")
Set MItem = OutlookApp.CreateItem(olMailItem)

' ****Test variable(s) to check Outlook msg formatting .. currently not
working
'Set TestOutlookEditor = ActiveInspector("Outlook.Application") 'set
option
not working .. commenting out
Set TestEditor = Inspector.WordEditor("Word.Application")

' Below is the section of code I am unable to get to work
' **********************
If TestEditor.Inspector.WordEditor = Null Then
MsgBox ("Pass") ' confirmation from Excel if value is true
Else
MsgBox ("Failed") ' confirmation from Excel if value is False
End If
' ********************** End of test code

TestHTMLString = "<font face=Arial><font size=2><color=#000000>Hello
Everyone,<br /><br />" & _
"<span style=background-color:#FF0000><font
color=#FFFFFF>Red</span>" & _
"<font color=#4B0082> = Hello new line.<br /> " & _
"<font color=#FF00FF>Testing<br />" & _
"<font color=#000000><dir>" & _
"<li>Line <b>2</b></dir><br />" & _
"Testing new line"

With MItem
.To = ""
.CC = ""
.Subject = "Test Email using HTML on " & Format(Now, "dddd
mm/dd/yy")
.htmlBody = TestHTMLString
.Display ' This allows the email to show vs auto
sending
End With

Set OutlookApp = Nothing
Set MItem = Nothing

End Sub


:

You can check if Inspector.WordEditor is a null object. That property
equates to the Document object in Word.

You can also check and change these settings in the registry:

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

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure,
MOSS
2007
& WSS 3.0 Application Development)
President
Collaborative Innovations
-> Try Picture Attachments Wizard 2.0 For Microsoft Outlook <-
-> Take your SharePoint content offline <-
-> More info: http://www.collaborativeinnovations.ca <-
Blog: http://blogs.officezealot.com/legault


Hello,

This is a follow-up post to what I have posted on another forum
(please
see:
http://www.microsoft.com/communitie...ming&mid=5c23ec0c-60ed-4b43-9302-81c2d86f3a13
); I was wondering if anyone here might have come across a similar
question.
I have thumbed through the threads that I thought were relevant and
have
tried a few variations but without any success.

What I am attempting to do is confirm through VBA whether or not
someone
has
the ‘Use Microsoft Office Word 2003 to edit e-mail messages’ option
selected
from their Outlook 2003 profile. The script that Ron devolved has a
caveat
where the ‘RangeToHTML’ function (see
http://www.rondebruin.nl/mail/folder3/mail4.htm for detail) will not
work
if
that option is selected. If the person has that option ‘active’ have
the
script turn it off .. if they don’t then the script will run as
normal.
Then
at the end put it back the way their options were of course;
assuming
since
it’s a script it won’t actually ‘change’ the end users Outlook
settings.

My problem stems from not understanding how to call ‘IsWordEditor’
module
/
class / etc correctly from Excel’s VBA GUI.

Thank you in advance for your help,

J
 
E

Eric Legault [MVP - Outlook]

The problem is the "IsWordEditor" method you're calling - there's no such
thing! Also, call ActiveInspector as below, and *after* the e-mail is
displayed:


Set OutlookApp = CreateObject("Outlook.Application")
Set MItem = OutlookApp.CreateItem(olMailItem)

With mItem
..display 'creates a blank email
Set TestOutlookEditor = Application.ActiveInspector
If TestOutlookEditor.EditorType = 4 Then '= olEditorType.olEditorWord
MsgBox ("Pass") ' confirmation from Excel if value is true
Else
MsgBox ("Failed") ' confirmation from Excel if value is False
End If
End with

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS 2007
& WSS 3.0 Application Development)
President
Collaborative Innovations
-> Try Picture Attachments Wizard 2.0 For Microsoft Outlook <-
-> Take your SharePoint content offline <-
-> More info: http://www.collaborativeinnovations.ca <-
Blog: http://blogs.officezealot.com/legault


J Smith 555 said:
Eric,

Sorry for the delay in the response, I have attempted to use the
suggestion
you gave to 'produce an active inspector window' using a with statement
(see
below).


Set OutlookApp = CreateObject("Outlook.Application")
Set MItem = OutlookApp.CreateItem(olMailItem)
Set TestOutlookEditor = ActiveInspector("Outlook.Application")

With mItem
.display ‘creates a blank email

If TestOutlookEditor.IsWordEditor = True Then
MsgBox ("Pass") ' confirmation from Excel if value is true
Else
MsgBox ("Failed") ' confirmation from Excel if value is False
End If
End with


I hate to say it but, at this point I am a little above my head trying to
figure out the command string needed to get the code to return a 'true /
false' or whatever would be needed so I can toggle the editor on / off.

Please let me know if you have any sample code that can retrieve the
editor.

Thank you again for your time,

J

Eric Legault said:
Are you sure you have an e-mail open? The Set MItem =
OutlookApp.CreateItem(olMailItem) call does not produce an active
inspector
window until you cal MItem.Display. You don't have error handling turned
off so you *should* get an error with the Set objWordDoc =
ActiveInspector.WordEditor call because ActiveInspector would be Nothing
if
there's no open message.

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure, MOSS
2007
& WSS 3.0 Application Development)
President
Collaborative Innovations
-> Try Picture Attachments Wizard 2.0 For Microsoft Outlook <-
-> Take your SharePoint content offline <-
-> More info: http://www.collaborativeinnovations.ca <-
Blog: http://blogs.officezealot.com/legault


J Smith 555 said:
Eric,

I implemented the code you suggested into my procedure and I am able to
'debug >> Compile VBAProject' without any troubles errors. What I am
running
into is that when I step through the code (regardless if I have Word
2003
as
my email editor selected or not) 'objWordDoc' always returns
'objWordDoc =
nothing' .. I have included my updated code (shortened slightly for
space
reasons) so you see what I see.

Thank you agian for your time,

Sub TestHTMLEmailEditor_MSDN()

Set OutlookApp = CreateObject("Outlook.Application")
Set MItem = OutlookApp.CreateItem(olMailItem)

Dim TestHTMLString As String

Dim objWordDoc As Word.Document
Set objWordDoc = ActiveInspector.WordEditor

If objWordDoc Is Nothing Then
MsgBox ("Word 2003 is NOT selected")
Else
MsgBox ("Word 2003 is the active email editor") 'This is Word Mail!
End If

TestHTMLString = "<font face=Arial><font size=2><color=#000000>Hello
Everyone,<br /><br />" & _
"<span style=background-color:#FF0000><font
color=#FFFFFF>Red</span><br />" & _
"<font color=#FFFFFF>Testing new line"

With MItem
.To = ""
.htmlBody = TestHTMLString
.Display ' This allows the email to show vs auto
sending
End With

Set OutlookApp = Nothing
Set MItem = Nothing
Set objWordDoc = Nothing

End Sub

:

This is how you should be testing:

Dim objWordDoc As Word.Document 'Make sure you have a reference set to
the
Microsoft Word 2003 Object Model

Set objWordDoc = ActiveInspector.WordEditor

If objWordDoc Is Nothing Then
'This isn't Word Mail
Else
'This is Word Mail!
End If

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure,
MOSS
2007
& WSS 3.0 Application Development)
President
Collaborative Innovations
-> Try Picture Attachments Wizard 2.0 For Microsoft Outlook <-
-> Take your SharePoint content offline <-
-> More info: http://www.collaborativeinnovations.ca <-
Blog: http://blogs.officezealot.com/legault


Eric,

Thank you for your quick reply, I have included a copy of the code I
am
working with so I can detail what error(s) I am getting. I am using
Excel
2003 with Outlook 2003 running on XP Pro SP2 (please see below)

This is the problem I am running into, I am unable to call the
'Inspector.WordEditor' correctly,
- If I 'Set TestOutlookEditor =
ActiveInspector("Outlook.Application")'
and
I go to 'Debug >> Compile VBAProject'. I get error msg 'Compile
error:
Sub
or
Function not defined' .. the debug highlights the word
'ActiveInsepctor'

- if I 'Set TestEditor = Inspector.WordEditor("Word.Application")' I
get
error msg 'Run-time errror '424': Object required' .. if I
'MouseOver'
the
word 'TestEditor' the debug says 'TestEditor = Empty'

My theory is this: if I can confirm that the end user (person
running
script) has their's set to 'True' then I can get the script to work
then
Ron's email script will work correctly, if the user has it set to
'False'
then the script will run without any troubles.

Sorry for not clarifing earlier.

Sub TestHTMLEmailEditor_MSDN()

'************ Test Code
' This creates an email with a preset list of people who request the
data.

Dim TestHTMLString As String

Set OutlookApp = CreateObject("Outlook.Application")
Set MItem = OutlookApp.CreateItem(olMailItem)

' ****Test variable(s) to check Outlook msg formatting .. currently
not
working
'Set TestOutlookEditor = ActiveInspector("Outlook.Application") 'set
option
not working .. commenting out
Set TestEditor = Inspector.WordEditor("Word.Application")

' Below is the section of code I am unable to get to work
' **********************
If TestEditor.Inspector.WordEditor = Null Then
MsgBox ("Pass") ' confirmation from Excel if value is
true
Else
MsgBox ("Failed") ' confirmation from Excel if value is
False
End If
' ********************** End of test code

TestHTMLString = "<font face=Arial><font
size=2><color=#000000>Hello
Everyone,<br /><br />" & _
"<span style=background-color:#FF0000><font
color=#FFFFFF>Red</span>" & _
"<font color=#4B0082> = Hello new line.<br /> " & _
"<font color=#FF00FF>Testing<br />" & _
"<font color=#000000><dir>" & _
"<li>Line <b>2</b></dir><br />" & _
"Testing new line"

With MItem
.To = ""
.CC = ""
.Subject = "Test Email using HTML on " & Format(Now, "dddd
mm/dd/yy")
.htmlBody = TestHTMLString
.Display ' This allows the email to show vs
auto
sending
End With

Set OutlookApp = Nothing
Set MItem = Nothing

End Sub


:

You can check if Inspector.WordEditor is a null object. That
property
equates to the Document object in Word.

You can also check and change these settings in the registry:

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

--
Eric Legault [MVP - Outlook]
MCDBA, MCTS (Messaging & Collaboration, SharePoint Infrastructure,
MOSS
2007
& WSS 3.0 Application Development)
President
Collaborative Innovations
-> Try Picture Attachments Wizard 2.0 For Microsoft Outlook <-
-> Take your SharePoint content offline <-
-> More info: http://www.collaborativeinnovations.ca <-
Blog: http://blogs.officezealot.com/legault


message
Hello,

This is a follow-up post to what I have posted on another forum
(please
see:
http://www.microsoft.com/communitie...ming&mid=5c23ec0c-60ed-4b43-9302-81c2d86f3a13
); I was wondering if anyone here might have come across a
similar
question.
I have thumbed through the threads that I thought were relevant
and
have
tried a few variations but without any success.

What I am attempting to do is confirm through VBA whether or not
someone
has
the ‘Use Microsoft Office Word 2003 to edit e-mail messages’
option
selected
from their Outlook 2003 profile. The script that Ron devolved has
a
caveat
where the ‘RangeToHTML’ function (see
http://www.rondebruin.nl/mail/folder3/mail4.htm for detail) will
not
work
if
that option is selected. If the person has that option ‘active’
have
the
script turn it off .. if they don’t then the script will run as
normal.
Then
at the end put it back the way their options were of course;
assuming
since
it’s a script it won’t actually ‘change’ the end users Outlook
settings.

My problem stems from not understanding how to call ‘IsWordEditor’
module
/
class / etc correctly from Excel’s VBA GUI.

Thank you in advance for your help,

J
 
J

J Smith 555

Eric,

Sorry for the long delay in response, I added the below code as suggest but
when I run it I am getting an error msg:

Run-time error '438':
Object doesn't support this property or method

When i dubug it highlights the line:

Set TestOutlookEditor = Application.ActiveInspector

and says that the 'TestOutlookEditor = Empty' .. I have attempted to 'Dim
TestOutlookEditor as Object (and Variant)' without any luck.

Am I missing something ??

Thank you agian for your time and help with this,

Jason
 
K

Ken Slovak - [MVP - Outlook]

If this code is running in the Outlook VBA project then Application means
Outlook.Application. If it's running somewhere else
Application.ActiveInspector means nothing. If you have an
Outlook.Application object OutlookApp then you should use
OutlookApp.ActiveInspector instead.
 
J

J Smith 555

Ken,

Sorry for not clarifying on my previous post. I am running the below code on
WIN XP SP2 / Excel '03 .. which is calling Outlook to send the email. I am
getting the same error on the same line of code (If
OutlookApp.ActiveInspector = True Then ..)

My Code:

Sub Test()

Set OutlookApp = CreateObject("Outlook.Application")
Set mItem = OutlookApp.CreateItem(olMailItem)

With mItem
.display 'creates a blank email
If OutlookApp.ActiveInspector = True Then ‘ Error ‘438
OutlookApp.ActiveInspector = False 'Turn off ActiveInspector
MsgBox ("Pass") ' confirmation from Excel if value is true
Else
MsgBox ("Failed") ' confirmation from Excel if value is False
End If
End With

End Sub

The overall goal is to send an email (through Excel) using .HTMLbody
formatting then attach inside the same body of the email a range of cells
with some formatting (ie a small layout of data) then more text using HTML.
On Ron’s website (Link : http://www.rondebruin.nl/mail/folder3/mail4.htm) he
mentions this :
<b>Note: This is not working if Word is your mail editor, you can change
this setting in Outlook: Tools>Options>…Mail Format tab </b>

There might be some other code out there but I have yet to come across it ..
What I was attempting to do using this post was to find out from using Excel
to call Outlook then determine if the WordEditor is active or not .. if its
active turn it off then use Ron's code to do what I want. The downside is the
code I'm working on will be used by others and I am trying to make sure that
the code is flexible enough to determine if WordEditor is active and make the
needed changes for the script to run correctly.

I have more experience with Excel VBA than Outlook VBA .. so I’m really lost
when it comes to the call functions and the syntax associated with Outlook.
:-(

If you know of some other code out there or can suggest another forum that
might steer by in the right direction let me know and I'll keep hunting. :-D

Thank you again for your time, any suggestions is greatly appreciated.

Jason
 
K

Ken Slovak - [MVP - Outlook]

I don't understand that code at all. ActiveInspector is an object, an
Inspector that happens to be active. It isn't a Boolean. It can be Nothing
or not but why are you trying to coerce it to a Boolean?

I'd either use a test like this:

If (OutlookApp.ActiveInspector Is Nothing) Then

or something like this:

If (OutlookApp.Inspectors.Count > 0) Then
'there is at least one Inspector open
 
J

J Smith 555

Ken,

Thank you again for the code, I was able to find a 'workaround' that might
work for what I am using but I come across a problem . If I need to open a
new thread let me know and I will repost as needed.

This is the code I have adapted to work for my needs (mostly)

Sub Test()

Set OutlookApp = CreateObject("Outlook.Application")
Set MItem = OutlookApp.CreateItem(olMailItem)

With MItem
.bodyformat = MailFormat.mfRTF
.body = "First line of Test"
.htmlbody = "<b> Second Line of Test </b>"
.Display
End With

End Sub

The problem I have is when I run this script the email that opens up only
has 'Second Line of Test' inside the body of the email. If I comment out the
line ".htmlbody = "<b> ..." then the email will show "First line of Test". Is
there a way to 'switch back and forth' inside an email between RTF and HTML
??

Jason
 
K

Ken Slovak - [MVP - Outlook]

You need to use only 1 or the other. If you write to HTMLBody after writing
to Body you end up overwriting Body. No way around that.
 
J

J Smith 555

Good to know.

Is there a way to about simply deselect the checkbox before the email is
created ???

I attempted to 'Record a Macro' then go to Tools >> Options >> Mail Formatget VBA to record that syntax. Would you happen to know what that is ?

If such a thing was 'recordable' then wouldn’t I be able to use the code i
have below to force the change using OutlookApp.whatever ??
 
K

Ken Slovak - [MVP - Outlook]

Word has a macro recorder but Outlook doesn't, and no recorder or pure code
can access the settings in the property page in the Options menu. Any
changes to the registry settings are read only on startup and then cached.
So there's no way around it. You can change the format but you cannot change
the editor.
 

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