Solved

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

Posted on 2009-05-12
13
374 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Automate switch config backup 3 70
Clear Filter 8 60
where to download correct copy of Scriptomatic 2.0 Scripting Guys 4 39
Having trouble with a VB Script 17 18
Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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