Solved

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

Posted on 2013-06-14
4
3,567 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 48

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 48

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

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

Outlook Free & Paid Tools
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

743 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

12 Experts available now in Live!

Get 1:1 Help Now