How to Change .HTMLBody Font Size to 12 pt? - html

I am trying to change the font size of certain parts of my email to size 12pt.
11pt and 13pt both work. When trying to set 12pt font it comes out at size 10pt.
Here is a portion of my code:
.HTMLBody = "Hello All,<br><br>" & _
"<B><U><font style=""font-size:13pt"">Incidents:</B></U></font><br><br>" & _
ES11Text & _
"<B><U>Non Intervention Incidents:</B></U><br><br>" & _
NonInterventionText & _
"<B><U>Hand-off:</B></U><br><br>" & _
"N/A<br><br>" & _
"<B><U>Escaltions:</B></U><br><br>" & _
Escalations & _
"Regards,<br>" & _
Signature

I figured it out. In my code to generate an email I wanted to include my signature at the bottom so I set a string equal to OutMail.HTMLBody before doing anything else and then concatenate that string to the end of my email which will add my signature. Doing this is what srews it up. If I don't include the signature, Times New Roman 12pt font works... Still doesn't make sense to me.

Related

Font size changed when email is sent

I am facing the following issue: when I send out a automated email the font size changes from 10 to 11. See below the code I am using:
With OutlookMailitem
.To = toEmail
.CC = ccEmail & ";" & ccEmail2 & ";" & ccEmail3
.Subject = "Submit your Timesheet"
.HTMLbody = "<p style='font-family:arial;font-size:13'>" & "Hey " & toName & "," & "<br/>" & "<br/>" & "We noticed your timesheet is still open. Please submit your timesheet each Monday before 12PM. If you face any issues, do let us know." & "<br/>" & "<br/>" & "Best," & signature
.Send
End With
Any idea what is causing this? Many thanks in advance.
Could you try using px.
<p style='font-family:arial;font-size:13px'>
You missed to add "px" or the unit that you want before the font-size, if this doesn't work... maybe another function is overwriting your styles, then try to add !important after the font-size: 13px like this:
<p style='font-family:arial;font-size:13px!important;'>
!important shall take priority over any other style that is applied.

Changing font size of the signature of an outlook email generated through VBA

i'm able to make the signature bold but i cant change the size. I can also change the size of the body but not the signature. I need to change the font size of the signature to match the font size of the body in the email.
Sub Email_Test()
'Exit function if user input incomplete:
If IsNull(Forms!frmCompMain!cboPayPrd) = True Then
MsgBox "Please provide the Pay Period parameter!", vbCritical
Exit Sub
End If
'-----------------------------------------
----'DECLARE AND SET VARIABLES
Dim myOutlok As Object
Dim myMailItm As Object
Dim Signature As String
Dim OtlApp As Object
Dim OtlNewMail As Object
Dim olMailItem As Object
Dim PayPrd As String
Set OtlApp = CreateObject("Outlook.Application")
Set OtlNewMail = OtlApp.CreateItem(0)
PayPrd = Forms!frmCompMain!cboPayPrd
'-----------------------------------------
-----'GET DEFAULT EMAIL SIGNATURE
Signature = Environ("appdata") & "\Microsoft\Signatures\"
If Dir(Signature, vbDirectory) <> vbNullString Then
Signature = Signature & Dir$(Signature & "*.htm")
Else:
Signature = ""
End If
Signature =
CreateObject("Scripting.FileSystemObject").GetFile(Signature).OpenAsTextStream(1, -2).ReadAll
'-----------------------------------------
----'CREATE EMAIL
OtlNewMail.HTMLBody = Signature
With OtlNewMail
.to = ""
.CC = ""
.Subject = ""
.HTMLBody = "<font size='2'> Hello," & "<br />" & _
"<br />" & _
"" & "<br />" & _
"<br />" & _
"<b>Production Period:</b> " & DateSerial(Year(PayPrd)" & _
"<br />" & _
"<b> Pay Date:</b> " & DateSerial(Year(PayPrd), Month(PayPrd) + 1, 10) &
"<br />" & _
"<br />" & _
"Please let me know if you have any questions." & "<br />" & _
"<br />" & _
"<b>" & Signature & "</b>"
.display
'.Send
End With
'-----------------------------------------
----'CLEANUP
End Sub
Firstly, you cannot concatenate two HTML strings and expect a valid HTML string back. The two must be merged.
Secondly, if the font size is explicitly set in the HTML signature, your code explicitly wrapping the signature in an element with a specified font size would do nothing. You'd need to use the HTMLDocument interface or the Word object model to set the size.
Or, the simplest possible solution, make sure the stationary signature already has the right font.
You should use the following code replace the .HTMLBody content:
Signature = "<b style='color:red;'>Your Sigature</b>"
With OutMail
.To = ""
.Subject = "This is the Subject line"
.HTMLBody = "<font style='font-size:20px !important;'> Hello <br /><br/><br/><b>Production Period:</b> DateSerial(Year(PayPrd)<br /><b> Pay Date:</b> DateSerial(Year(PayPrd), Month(PayPrd) + 1, 10)<br/><br/>Please let me know if you have any questions.<br/><br/><b style='font-size 14px !important'>" & Signature & "</b></font>"
.Display
If the font size is set in the HTML signature, You'd need to use the HTMLDocument interface to set the size.

Font style for e-mail body in VBA

I have the following code written in VBA:
Dim StrBody As String
StrBody = "Text Line 1" & "<br>" & _
"Text Line 2" & _
How do I change the font to get a particular style (e.g. Arial), size, and color?
The text is used as the body of an e-mail. That's why some better looking style needs to be used. The default font is "Times New Roman".
I imagine you would have to use the font tag and its various attributes:
StrBody = "<font size=""10"" face=""Arial"" color=""red"">" & _
"Text Line 1" & "<br>" & _
"Text Line 2" & _
"</font>"
Make sure the " quotes used to surround HTML attribute values don't get interpreted as the end of the VBA string: escape them by writing "" instead, as in the example above.
color can also be specified as hexadecimal RGB codes. So color="red" could be replaced by the more general color="#FF0000".

Signature needs to be in RTF instead of HTML. Passing in from VB6 to Outlook

I was passing a string of HTML formatted text for a signature in VB6 to Outlook but on certain very old computers with very old versions of outlook it was running into a problem where hypens would start a new line, or if I used the tag to fix it then word wrap would be totally turned off.
I want to try to use RTF instead hoping that this will fix the problem. However I still have that signature that is in HTML and I need to pass it in as a string into Outlook using Rich Text formatting. I can't find any good resources on this or if it is even possible, whenever I try they show up with the escape commands and everything.
My current HTML string:
string = vbCrLf & vbCrLf & "<B><FONT face=Arial color=#365f91 size=2>" & _
strName & "</FONT>" & _
"<FONT face=Arial size=2><BR>" & _
"<I>" & strPosition & "</I>" & _
"</FONT></B><BR/><B><FONT face=Arial size=2>" & _
strAddress1 & "</FONT></B><BR/><FONT face=Arial size=1>" & _
strAddress2 & "<BR>" & strCity & ", " & _
strProvince & ", " & strPostalCode & _
"<BR>" & strCountry & "<BR>Office: " & strPhone & _
"<BR>" & strEmail & "<BR>www.website.com<BR>" & _
" " & _
"<I><FONT face=Arial size=2>" & strImageCaption & "</FONT>" & _
"<BR/><BR/><BR/></I><FONT face=Arial size=1>" & strDisclaimer & _
"</FONT></P>"
Anyone able to help me pass this in as rtf or know of anyway I could do this? Will be very appreciated!
EDIT: Alternatively if anyone knows how to fix the issue with word-wrap/line-breaking hyphens I would love that too.
This can be the RTF template idea, produced by wordpad and slightly altered. I assume you can mixin the VB stuff to replace the variable text.
To get this:
Hello
postion
My‑street
Mystreet 2
My city
My disclaimer
( I don't how to do color in SO markup but in the RTF the first line in RED and My disclaimer is one point smaller)
use this RTF:
{\rtf1\ansi\ansicpg1252\deff0\deflang1043{\fonttbl{\f0\fnil\fcharset0 Arial;}}
{\colortbl ;\red255\green0\blue0;}
\cf0\b\fs22 Hello\par
\cf0\b0\i\fs24 postion\par
\i0 My\_street\par
Mystreet 2\par
My city\par
\fs22 My disclaimer\par
\f1\par
}
between My and street I placed a non breaking hyphen, according to the RTF specs. In html the same could be achieved by using
‑

XML / HTML Email Template for Error Reporting

I want to create a template with XML or HTML with placeholders for exception reporting variables to be swapped in at runtime when an exception occurs. I like what I've got so far with the template, and behavior, but it's all hard coded at the moment, so bad.
Here's a sample of the code I have...
'Styling (Outlook does not follow CSS standards >:-( )
body = "<html><head>" & _
"<style type=""text/css"">" & _
" * {font:12px Arial, Helvetica, sans-serif;}" & _
" table {border-collapse:collapse;}" & _
" table.grid td {padding:0 7px;border:solid #ccc 1px;}" & _
" .bold {font-weight:bold;padding-right:12px;}" & _
"</style></head><body>"
'Partial template
body &= "<table><tr><td class=""bold"">Error:</td><td>" & ex.Message & "</td></tr>" & _
"<tr><td class=""bold"">Exception:</td><td>" & ex.GetType().FullName & "</td></tr>" & _
"<tr><td class=""bold"">Source:</td><td>" & ex.Source & "</td></tr>" & _
"<tr><td class=""bold"">Request Url:</td><td>" & Request.Url.ToString & "</td></tr></table><br />"
Notice the ex.Message variable, etc. I want to move all the HTML code into a separate file (XML or HTML, depending on what is recommended, XML I imagine?) along with placeholders for each of the error variables. Then load the template, substitute in the variables and send the email on the fly. What is the best practice for doing this?
Also, please don't try to fix my CSS, that's not what this question is about. Outlook doesn't follow standards (go figure), and this is how I had to do it.
Thanks. ;)
I think you are pretty much on the right way. The steps would be:
Extract the templates into a resource file (the resource extension .xml, .html is the actual resource type).
Replace the variable concatenations with tokens; So would be:
(...)<tr><td class="bold">Source:</td><td>{exSource}</td></tr>(...)
Create an extension method to String objects to "enhance" the String.Format, so you could do something like
' Load the resourceFile and put content into formattedBody
Dim formattedBody as String = templateBody.FormatWith(New With{.exSource = ex.Source})
About how to implement the FormatWith, take a look here.
This answer may help you as well.