Solved

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

Posted on 2009-05-12
13
366 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

778 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