Solved

VBA Outlook Email HTMLBody

Posted on 2013-01-23
2
4,410 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remaiā€¦
Read this checklist to learn more about the 15 things you should never include in an email signature.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabilā€¦
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

863 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

25 Experts available now in Live!

Get 1:1 Help Now