Solved

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

Posted on 2009-05-12
13
341 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
  • 7
  • 6
13 Comments
 
LVL 76

Expert Comment

by:David Lee
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 76

Expert Comment

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

Author Comment

by:jamiepryer
Comment Utility
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
Comment Utility
"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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jamiepryer
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You're welcome.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now