Solved

VBA Outlook Email HTMLBody

Posted on 2013-01-23
2
4,541 Views
Last Modified: 2013-01-24
Hi,

I am sending an e-mail though outlook by using VBA. However the formatting is not very good. I know I can use HTML to help format the text.

I wanted to know if it was possible to create a html table as I have 5 fields. Each field can contain strings of different lengths so at the moment it doesn't look very nice. Please see below an example. The first line is the headers the other rows are the actual data. What is the best way to display/format this data?


ISIN            Security                Field           Old Value               New Value



CA135087YF56            CANADIAN GOVT 4% 01/06/17               Moody LT Issue Rating           Aaa             B3              

CA135087YF56            CANADIAN GOVT 4% 01/06/17               SandP LT Issue Rating           AAA             CCC+            

AT0000383864            AUSTRIAN GOVERNMENT 6.25% 15/07/27              Moody LT Issue Rating           Aaa             CCC+  



Thanks,

M
0
Comment
Question by:mcs26
2 Comments
 
LVL 52

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 250 total points
ID: 38812708
With html email you need to style things old school with your table s and styles  need to be done inline and not via a style sheet.

http://www.w3schools.com/css/default.asp http://coboldinosaur.com/pages/table-art.html  (no javascript though)

    <td style="background-color:#C06; color:#FFFFFF; font-family:Verdana, Geneva, sans-serif; font-size:14px">Hi there world!</td>

or <td><span style=style="background-color:#C06; color:#FFFFFF; font-family:Verdana, Geneva, sans-serif; font-size:14px">Stuff to say</span></td>


I think styling the td's is the better choice.
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 250 total points
ID: 38813240
It all depends on how much effort you want to put into it ... for example via HTML the first two rows of your request could be generated by:

Sub html1()
Dim olkApp As Object
Dim olMailItem As Object

    Set olkApp = Application
    Set olMailItem = olkApp.CreateItem(0)
    With olMailItem
        .BodyFormat = 2
        .To = "xyz@abc.com"
        .Subject = "TBD - Subject"
        .HTMLBody = ""
        .HTMLBody = .HTMLBody & "<BR>"
        .HTMLBody = .HTMLBody & "<table BORDER=1 WIDTH=80%>"
        .HTMLBody = .HTMLBody & "<tr>"
        .HTMLBody = .HTMLBody & "<td WIDTH=15%>"
        .HTMLBody = .HTMLBody & "ISIN"
        .HTMLBody = .HTMLBody & "</td>"
        .HTMLBody = .HTMLBody & "<td WIDTH=25%>"
        .HTMLBody = .HTMLBody & "Security"
        .HTMLBody = .HTMLBody & "</td>"
        .HTMLBody = .HTMLBody & "<td WIDTH=25%>"
        .HTMLBody = .HTMLBody & "Field"
        .HTMLBody = .HTMLBody & "</td>"
        .HTMLBody = .HTMLBody & "<td WIDTH=15%>"
        .HTMLBody = .HTMLBody & "Old Value"
        .HTMLBody = .HTMLBody & "</td>"
        .HTMLBody = .HTMLBody & "<td WIDTH=15%>"
        .HTMLBody = .HTMLBody & "New Value"
        .HTMLBody = .HTMLBody & "</td>"
        .HTMLBody = .HTMLBody & "</tr>"
        
        .HTMLBody = .HTMLBody & "<tr>"
        .HTMLBody = .HTMLBody & "<td>"
        .HTMLBody = .HTMLBody & "CA135087YF56"
        .HTMLBody = .HTMLBody & "</td>"
        .HTMLBody = .HTMLBody & "<td>"
        .HTMLBody = .HTMLBody & "CANADIAN GOVT 4% 01/06/17"
        .HTMLBody = .HTMLBody & "</td>"
        .HTMLBody = .HTMLBody & "<td>"
        .HTMLBody = .HTMLBody & "Moody LT Issue Rating"
        .HTMLBody = .HTMLBody & "</td>"
        .HTMLBody = .HTMLBody & "<td>"
        .HTMLBody = .HTMLBody & "Aaa"
        .HTMLBody = .HTMLBody & "</td>"
        .HTMLBody = .HTMLBody & "<td>"
        .HTMLBody = .HTMLBody & "CCC+"
        .HTMLBody = .HTMLBody & "</td>"
        .HTMLBody = .HTMLBody & "</tr>"
        
        .HTMLBody = .HTMLBody & "</table>"
        .Display
    End With

End Sub

Open in new window


You can of course tweak the parameters and the second row can be cloned to create multiple rows.

Chris
0

Featured Post

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)

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

773 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