Solved

MODIFY FORMAT AND COLOR IN A OUTLOOK MESSAGE FROM EXCEL USING VBA

Posted on 2013-06-14
4
3,776 Views
Last Modified: 2013-06-14
Hi,

I am using a VBA code to send emails using outlook from excel VBA, I want to be able to modify some parts of the body like changing color, font...? Is this possible?
0
Comment
Question by:joyacv2
  • 2
  • 2
4 Comments
 
LVL 49

Expert Comment

by:Rgonzo1971
ID: 39247574
Hi,

it is possible to do it by sending an HTML Text

Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties.

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

    With objMail
       'Set body format to HTML
       .BodyFormat = olFormatHTML
       .HTMLBody = "<HTML><BODY>Enter the <b>message</b> text here. </BODY></HTML>"
       .Display
    End With
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:joyacv2
ID: 39247651
Hi

Do you know how specify a color in this code?
0
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39247695
Hi,

Please refer to

http://html-color-codes.info/#How_to_use_html_color_codes

Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties.

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

    With objMail
       'Set body format to HTML
       .BodyFormat = olFormatHTML
       .HTMLBody = "<HTML><BODY><span style=""color:#80BFFF"">Enter</span style=""color:#80BFFF""> the <b>message</b> text here. </BODY></HTML>"
       .Display
    End With
End Sub

Open in new window

Regards
0
 
LVL 1

Author Closing Comment

by:joyacv2
ID: 39247734
Excellent Solution
0

Featured Post

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!

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
Read this checklist to learn more about the 15 things you should never include in an email signature.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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