• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

VBA to create new email in Outlook using different font, font size & colour|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / VBA to create new email in Outlook using different font, font size & colour|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosVBA to create new email in Outlook …
sp_PrintTopic sp_TopicIcon
VBA to create new email in Outlook using different font, font size & colour
Avatar
Excel Rookie
Member
Members
Level 0
Forum Posts: 15
Member Since:
August 22, 2015
sp_UserOfflineSmall Offline
1
January 17, 2018 - 9:03 am
sp_Permalink sp_Print

Hello All and Happy 2018!

Can I please have a code to create a new e-mail message, contact, or calendar invite, the format will be in HTML, and use font - Times Roman, font size - 11, and font colour - blue. The code should also work when replying, forwarding, accepting etc. For the latter (responding/forwarding/accepting) I don’t mind if this is a separate code, though ideally would like it all to be in one.

I use Outlook 2013.

Thank you.

ER

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
2
January 17, 2018 - 1:53 pm
sp_Permalink sp_Print

Why do you need codes when you can change the setting in Outlook itself?

(Outlook 2010) File - Options - Mail - Stationery and Fonts...

Avatar
Excel Rookie
Member
Members
Level 0
Forum Posts: 15
Member Since:
August 22, 2015
sp_UserOfflineSmall Offline
3
January 18, 2018 - 1:02 am
sp_Permalink sp_Print

Hello SunnyKow,

Thank you for your suggestion.

I know about the Options feature, and the ability to change formatting from there. The code is needed as there is a default setting that is returns the original format settings. I have to change the Options with each log in (several times a day) or manually with each message/invite/contact (new, forward, reply, etc). A code is more efficient, and hopefully someone can please submit one for me? PLEASE!

Thanks for taking the time to suggest.

 

ER

Avatar
Anders Sehlstedt
Eskilstuna, Sweden

VIP
Members


Trusted Members
Level 3
Forum Posts: 870
Member Since:
December 7, 2016
sp_UserOfflineSmall Offline
4
January 18, 2018 - 8:34 am
sp_Permalink sp_Print

Hello,

I suggest that you take a look at this blog post and then adapt the code you see being used to your need. It is a good way to learn new things. Good luck!

Br,

Anders Sehlstedt

Avatar
Excel Rookie
Member
Members
Level 0
Forum Posts: 15
Member Since:
August 22, 2015
sp_UserOfflineSmall Offline
5
January 23, 2018 - 1:58 am
sp_Permalink sp_Print

Hi Anders,

Thank you for the suggested link to practice and create my own script. I came up with the one below which creates a new HTML email message but does not override the default font/size/colour.

Can you please see where it needs editing?

Thanks

ER

Sub createnewmessage()

'Create an Outlook object and new mail message

Set OutlookApp = CreateObject("Outlook.Application")

Set OutlookMail = OutlookApp.CreateItem(0)

 

'Display email and specify To, Subject, etc

With OutlookMail

 

.Display

.To = Email_To

.CC = Email_CC

.BCC = Email_BCC

.Subject = EmailSubject & CurrentMonth

Dim objMail As MailItem

On Error Resume Next

 

Set objItem = Application.ActiveInspector.CurrentItem

If Not objItem Is Nothing Then

    If objItem.Class = olMail Then

        Set objMail = objItem

        .HTMLBody = .HTMLBody

        Dim StrAgnt As String

StrAgnt = "<HTML><H2>The body HTML.</H2><BODY>Hi. </BODY></HTML>" & vbCrLf & vbCrLf & _

    Selection.WholeStory

    Selection.Copy

    Selection.WholeStory

    Selection.Font.Name = "Tahoma"

    Selection.Font.Size = 11

    Selection.PasteAndFormat (wdFormatSurroundingFormattingWithEmphasis)

    Selection.Delete Unit:=wdCharacter, Count:=1

    End If

End If

 End With

End Sub

Avatar
Excel Rookie
Member
Members
Level 0
Forum Posts: 15
Member Since:
August 22, 2015
sp_UserOfflineSmall Offline
6
January 24, 2018 - 8:29 am
sp_Permalink sp_Print

Hi again,

Could someone please check the code and offer a solution? It does not update the font.

Thank you,

ERCry

Avatar
Anders Sehlstedt
Eskilstuna, Sweden

VIP
Members


Trusted Members
Level 3
Forum Posts: 870
Member Since:
December 7, 2016
sp_UserOfflineSmall Offline
7
January 25, 2018 - 8:58 am
sp_Permalink sp_Print

Hi,

As I don't write VBA myself I am not really correct person to give advice, but I do know enough to be able to understand what the code is supposed to do. You are referencing to the .HTMLBody property, so should you then not use HTML to format the text? Either change to use .RTFBody property and see if it works with the existing formatting code or use HTML code to format the text in the body section. If you use .RTFBody then I suppose you need to remove the HTML tags in your StrAgnt.

I checked the MSDN pages for more information about syntax. In the example there they use a different object declaration. Do try their approach.

Br,

Anders

Avatar
Excel Rookie
Member
Members
Level 0
Forum Posts: 15
Member Since:
August 22, 2015
sp_UserOfflineSmall Offline
8
January 27, 2018 - 1:18 am
sp_Permalink sp_Print

nothing worked CryCry

Perhaps because I really am not experienced in any VBA, and should really know how to even read code.

Is there anyone who can help me, please?

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
9
January 27, 2018 - 6:32 pm
sp_Permalink sp_Print sp_EditHistory

Hi ER,

All you have to do is to use HTML formats, to set up the message body font, color and other attributes. The following text will work in VB editor:

.HTMLBody = "

" & "Text 1" & "

" & vbNewLine & _
            "

" & "Text 2" & "

" & vbNewLine & _
            "

" & "Text 3" & "

"

 

See more at: html-text-style-attributes

You can play around with formattings here:

http://htmledit.squarefree.com

Note that "

" & "Text 1" & "

" & vbNewLine cannot be used as is in HTML editor, replace the pairs of double quotes with one double quote, and remove single quotes:

Text 1

Later Edit:

Browsers will not display correctly the formatted text, see attached text file for a correct text sample.

Avatar
Excel Rookie
Member
Members
Level 0
Forum Posts: 15
Member Since:
August 22, 2015
sp_UserOfflineSmall Offline
10
February 2, 2018 - 2:44 am
sp_Permalink sp_Print

Thank you Catalin.

I will give it a try and get back to you.

ER

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Andy Kirby, RAMEZ ATTAR, Vincent Malone II, Uwe von Gostomski
Guest(s) 11
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
John Chisholm
vexokeb sdfg
John Jack
Malcolm Toy
Ray-Yu Yang
George Shihadeh
Naomi Rumble
Uwe von Gostomski
Jonathan Jones
drsven
Forum Stats:
Groups: 3
Forums: 24
Topics: 6212
Posts: 27236

 

Member Stats:
Guest Posters: 49
Members: 31889
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.