Solved

How do I change font within email generated by vba?

Posted on 2011-09-12
7
3,821 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

728 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