Link to home
Start Free TrialLog in
Avatar of jamiepryer
jamiepryerFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

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

Avatar of David Lee
David Lee
Flag of United States of America image

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

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

Avatar of jamiepryer

ASKER

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..
How does this setting affect the automated generation of emails?
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.
"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.
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
I agree.  How does the editor affect that if the attachments are being inserted by code?  Or are you inserting them manually?
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

ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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 :)
You're welcome.