Solved

VB code to set the outlook -> Option -> Mailformat -> user microsoft office word 2003 to edit email messages

Posted on 2009-05-12
13
379 Views
Last Modified: 2012-05-06
hi,
im trying to turn the folloiwng option on, with VB code, in outlook (from excel code)

- tools
-- options
---- mail format
----- user microsoft office word 2003 to edit email messages

i have the following code to check if this IS set, however i need to have a way to set it if not, rather then just a msgbox
Set myOlApp = CreateObject("Outlook.Application")
Set MyItem = myOlApp.CreateItem(olMailItem)
Set MyInspector = MyItem.GetInspector
If MyInspector.IsWordMail Then
Else
   'turn it on!!
End If

Open in new window

0
Comment
Question by:jamiepryer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 24363758
Hi, jamiepryer.

That is controlled by the following registry setting

HKCU\Software\Microsoft\Office\11.0\Outlook\Options\Mail\EditorPreference

The code below will set the editor as you requested.  You have to do this before Outlook starts or restart Outlook for the change to be seen.
Dim objShell As New WshShell
objShell.RegWrite "HKCU\Software\Microsoft\Office\11.0\Outlook\Options\Mail\EditorPreference", 131073, "REG_DWORD"
Set objShell = Nothing

Open in new window

0
 
LVL 76

Expert Comment

by:David Lee
ID: 24363770
Oops.  The code above is for VBA.  The code below is for VBScript.
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.RegWrite "HKCU\Software\Microsoft\Office\11.0\Outlook\Options\Mail\EditorPreference", 131073, "REG_DWORD"
Set objShell = Nothing

Open in new window

0
 

Author Comment

by:jamiepryer
ID: 24364218
thanks, is there any way to get around this without opening/closing outlook?

My code i run to generate emails seems to work fine, however it randomly seems to bug out after about 150 (ish) emails have been generated and it seems to be because this setting has been turned off?!

any suggestions..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 76

Expert Comment

by:David Lee
ID: 24364250
How does this setting affect the automated generation of emails?
0
 

Author Comment

by:jamiepryer
ID: 24365012
because my emails are all in richtext and not html
they need to be richtext for some of things i do such as using the word editor to do a find/replace on set items.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24365170
"they need to be richtext"
The selected editor doesn't control what format items are created in when creating them via code.  That's controlled by the BodyFormat property of each message.
0
 

Author Comment

by:jamiepryer
ID: 24372836
agreed
however if the emails are not richtext, when i add an attachment, it wont be placed within the document.

For attachments:
html emial: just gets added as an "attachment" (shown below hte subject in its own bar)
richtxt email: placed within the email in the location you specify
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24372947
I agree.  How does the editor affect that if the attachments are being inserted by code?  Or are you inserting them manually?
0
 

Author Comment

by:jamiepryer
ID: 24373170
the code add them, i use this to add the attachement and play about with buzz words:


With WordDoc.Range.Find
            .Text = "<Application>"
            .Replacement.Text = ApplicationName
            .Execute Replace:=wdReplaceAll
        End With
        With WordDoc.Range.Find
            ManagerFirstName = Trim(ManagerFirstName)
            .Text = "<Line Manager>"
            .Replacement.Text = ManagerFirstName
            .Execute Replace:=wdReplaceAll
        End With
        With WordDoc.Range.Find
            If CalDate = "" Then
                .Text = " by <Date>"
                .Replacement.Text = ""
                .Execute Replace:=wdReplaceAll
            Else
                .Text = " by <Date>"
                .Replacement.Text = " by " & CalDate
                .Execute Replace:=wdReplaceAll
            End If
        End With
        
        'add the attachment to the document
        Set wdRange = WordDoc.Range
        If wdRange.Find.Execute("<Attachment>") Then
            wdRange.Text = "" 'delete the pilot text
            wdRange.InsertFile TmpString
        End If

Open in new window

0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 24403138
We need to check two things.

1.  Is the message format changing?  If the messages are created and the BodyFormat property set to olRTF, then they should be in rich-text format.

2.  Is the Editor Preference setting changing?  If as you say, "... it randomly seems to bug out after about 150 (ish) emails have been generated", then is it because the editor has changed?  To test this, run your process and when it fails go check this setting and see if it has actually changed.  
0
 

Author Comment

by:jamiepryer
ID: 24410079
ok, will do, ive set hte bodyformat to be:    SafeItem.BodyFormat = olFormatRichText

i will test again in the next couple of days nad see where there bug happens
0
 

Author Closing Comment

by:jamiepryer
ID: 31580486
Thanks for the help.
I set hte richtext format and also (as per another question asked) saved all the emails in an archive folder.
I just run the code for 250 emails and its worked fine!
so fingers crossed thats done it :)
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24443796
You're welcome.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question