Solved

VBA Outlook Email HTMLBody

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

730 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