Solved

VBA Outlook Email HTMLBody

Posted on 2013-01-23
2
4,246 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
Comment Utility
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
Comment Utility
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.

Join & Write a Comment

Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

762 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

13 Experts available now in Live!

Get 1:1 Help Now