Solved

How do I change font within email generated by vba?

Posted on 2011-09-12
7
3,075 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

758 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

21 Experts available now in Live!

Get 1:1 Help Now