Solved

How do I change font within email generated by vba?

Posted on 2011-09-12
7
3,579 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
  • 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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