Solved

How do I change font within email generated by vba?

Posted on 2011-09-12
7
3,664 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 250 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 250 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find first method with 2 variable search criteria 10 43
Calculation in a Report 13 36
Combo box question 6 49
Ms Access 2010 Setup (Executable file) 4 61
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

737 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