Solved

Set HTML editor as default Editor Type (VBA)

Posted on 2004-08-30
8
845 Views
Last Modified: 2013-12-16
I am using a excel worksheet, I need, using VBA, to set html as the editor type for all messages that will be send. I mean as default editor type,

0
Comment
Question by:mgs1998
  • 4
  • 3
8 Comments
 
LVL 13

Expert Comment

by:stefri
ID: 11936208
in your vba code, use mail.HTMLBody to set the HTML code
It has to be fully compliant with HTML standard.


Stefri
0
 

Author Comment

by:mgs1998
ID: 11940953
Do you have the full code? since from opening outlook from excel until set htlm editor as default.
0
 
LVL 13

Expert Comment

by:stefri
ID: 11947181
open excel, open vba
add a ref to ms outlook
try this piece of code from one of my example which I had to slaughter a little to give you an idea

Public Sub createAmail()


Dim olApp As Outlook.Application
Dim theMail As Outlook.MailItem


    olExist = True
    On Error Resume Next
    Set olApp = GetObject(, "Outlook.Application")

    If Err.Number <> 0 Then
        olExist = False
        Err.Clear
        On Error Resume Next
        If Not IsEmpty(olApp) Then
            Set olApp = CreateObject("Outlook.Application")
        End If
       
        If Err.Number <> 0 Then
            Err.Clear
            MsgBox "Cant start Outlook", vbCritical, "Error"
            Exit Sub
        End If
    End If

    Set myNamespace = olApp.GetNamespace("MAPI")

    Set themail = olApp.CreateItem(olMailItem)
    theBody = "<html><title>my first test</title><body><p><B>My first Test</b></p></html>
    theMail.HTMLBody = theBody

    theMail.Recipients.Add "jdoe@xxx.com"
    theMail.Display True
    'theMail.Send
    set theMail = nothing
    set myNamespace = nothing

    If olExist = False Then
        olApp.Application.Quit
        Set olApp = Nothing
    End If

End Sub
stefri
PS: it will not set HTML default editor but will create a mail using HTML format
Setting HTML as editor is from
olApp.ActiveInspector.editorType
can be one of the following value:

    Const PlainText = 1
    Const HTML = 2
    Const RTF = 3
 
0
 

Author Comment

by:mgs1998
ID: 11952766
Almost perfect but when I am setting HTML as default editor a message appear telling that is not possible to set that property in a read-only property. Any solution?????


Help please...
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 13

Accepted Solution

by:
stefri earned 500 total points
ID: 11956274
Bad luck... read only property
Why do you want to set the editorType with a specific value?
You cant use bodyformat property of a mail item
See OL Help below
BodyFormat Property

Returns or sets an OlBodyFormat constant indicating the format of the body text. The body text format determines the standard used to display the text of the message. Microsoft Outlook provides three body text format options: Plain Text, Rich Text and HTML. Read/write OlBodyFormat.

OlBodyFormat can be one of these OlBodyFormat constants.
olFormatHTML
olFormatPlain
olFormatRichText
olFormatUnspecified

expression.BodyFormat

expression   Required. An expression that returns one of the objects in the Applies To list.

Remarks
All text formatting will be lost when the BodyFormat property is switched from RTF to HTML and vice-versa.

The property can not be set to olFormatUnspecified, however it will return olFormatUnspecified if the item has not yet been displayed.

Example
The following example creates a new MailItem object and sets the BodyFormat property to olFormatRichText. The Body text of the Mail item will now appear in Rich Text format.


Sub NewMail()
'Creates a new Mailitem and modifies its properties

    Dim olApp As Outlook.Application
    Dim objMail As MailItem
    Set olApp = Outlook.Application
    'Create mail item
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
       .DownloadState = olHeaderOnly
       'Set body format to Rich Text
       .BodyFormat = olFormatRichText
       .Display
    End With

End Sub

stefri
0
 

Author Comment

by:mgs1998
ID: 11956582
I have to write a macro that enable a signature, nevertheless to insert this signature I have to enable HTML editor(Signature contains picture)This macro will go to the event workbooks_open, when somebody open this excel file it will set up html editor and modify the signature.....
0
 
LVL 13

Expert Comment

by:stefri
ID: 11960956
I am afraid you cant modify the editor type but you can create a mail using html format
fill the html body as mentionned before and force the message format  with bodyformat set to olFormatHTML
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 23805160
"BodyFormat = olFormatRichText" seems not available on Outlook 2000: how can I do then to set the email editori previously?
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Use email signature images to promote corporate certifications and industry awards.
If you don't know how to downgrade, my instructions below should be helpful.
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

757 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

19 Experts available now in Live!

Get 1:1 Help Now