Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I change font within email generated by vba?

Posted on 2011-09-12
7
Medium Priority
?
4,238 Views
Last Modified: 2012-05-12
Dim objOL As Object
Dim objMail As Object
Set objOL = CreateObject("Outlook.Application")
Set objMail = objOL.CreateItem(olMailItem)

strBody = "Attached, please find a copy of the " &  NameofCompanyBolded & _
" letter for your review, and an electronic version of the Questionnaire.  A paper copy of these documents is also being sent to you." & vbCrLf & vbCrLf & _
"Please let me know if you have any questions."

objMail.To = strTo
objMail.CC = strCC
objMail.BCC = strBcc
objMail.Subject = strSubject
 
'Display Email
objMail.Display

objMail.body = strBody & objMail.body & vbCrLf & AfterSignatureCCs

I closed this question prematurely without the following question having been answered.

Questions:
1)  How do I set the font of the email text to Calibri 11 pt.?
0
Comment
Question by:newbie46
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 26

Expert Comment

by:Nick67
ID: 36525499
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36525717
<No Points wanted>

HTML like this:
<p style="font-size:7pt; font-family:calibri;">This is Calibri Text 7 point</p>

Will produce what you are asking for: Calibri font at 7 points
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36525740
So to do a complete block of text with line breaks, <br>, would start out like this:

<p style="font-size:7pt; font-family:calibri;">This is Calibri Text 7 point on line 1<br>This is Calibri Text 7 point on line 2</p>
0
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!

 

Author Comment

by:newbie46
ID: 36529048
boaq2000,
Where does the  <p style .... go? Is it added as seen below?

objMail.HTMLbody = <p style="font-size:7pt; font-family:calibri;">This is Calibri Text 7 point</p> & 
strBody & objMail.body & "<br>" & AfterSignatureCCs
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 1000 total points
ID: 36529890
My presumption here was that if you needed this level of text control that you understood how HTML is used in conjunction with "escape characters" to be encapsulated in a VBA string...

Again, this is why Nick recommended not trying to micromanage this....
...again, Too much trouble, and possibly not worth the effort unless you need something really basic.

In any event,
...The entire HTML block is a string and must be enclosed in double quotes.  This means that the quotes inside the HTML must be "escaped" with single quotes.
For example, this works fine for me.
             objMail.htmlBody = "<p style='font-size:7pt; font-family:calibri;'>This is Calibri Text 7 point on line 1<br>This is Calibri Text 7 point on line 2</p>"

(bear in mind that not all HTML will follow this pattern, so again you will have to understand how to build HTML inside VBA if you need to go further than this.)

;-)

JeffCoachman
0
 
LVL 26

Assisted Solution

by:Nick67
Nick67 earned 1000 total points
ID: 36530943
As Jeff has pointed out, the HTMLBody must be a single VBA String
It must contain ALL the properly formatted HTML you want in the body of the email message
As mega-quotes and  & _ are not my thing, I  would attack it like this

Dim myBody as string
myBody = "<p style='font-size:7pt; font-family:calibri;'>"
myBody = myBody & "This is Calibri Text 7 point on line 1<br>"
myBody = myBody & "This is Calibri Text 7 point on line 2</p>"
myBody = myBody & "<br><br>"

myBody = myBody & "<p style='font-size:11pt; font-family:Times New Roman;'>"
myBody = myBody & "Now I have switched to 11 point Times New Roman<br>"
myBody = myBody & "To do what you want you must know how to create HTML<br>"

objMail.HTMLbody = mybody

Attached is a little htm file that you can play with


testHTML.htm
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36531303
^
Yes, use Nicks syntax.

My post was just and example of a short string...
;-)
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

721 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