Solved

CSS Styling Outlook VBA HTML Email

Posted on 2007-04-06
4
3,585 Views
Last Modified: 2008-02-01
I have been given the task of styling an HTML email generated by Office
Outlook 2003 VBA Language

Stylewise, I would like to get some perspective on what is possible or not
possible with this.


I have also heard that there are changings coming in Outlook 2007 which
will render HTML email using the MS Word engine, dropping the use of IE
for this purpose.

http://developers.slashdot.org/developers/07/01/13/1911226.shtml

http://msdn2.microsoft.com/en-us/library/aa338200.aspx#Word2007MailHTMLandCSS2_IntroductiontoHTMLandCSSCapabilitiesinOutlook



The examples about OutLook VBA on the Microsoft Web site are very simplistic
'Set the HTMLBody of the item.
    Item.HTMLBody = "<HTML><H2>My HTML page.</H2><BODY>My
body.</BODY></HTML>"
    'Item displays HTML message.
    Item.Display


So my question would be can you use use css formating?
If so where do you state it or import it?


Could the a Item.HTMLBody = be modified to include:

<head>
<title>Untitled Document</title>
<style type="text/css">
<!--
.style3 {font-size: 12px}
-->
</style>
</head>

Or is the formatting done in an older way whereby the font and background
colors are stuffed in side the table cells?
0
Comment
Question by:LT1415
  • 2
4 Comments
 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 165 total points
ID: 18867904
Yes, you can use CSS formating.  The Style declarations go in the usual spot, in the HEAD portion of the HTML document.  The style declarations really need to be in the HTML document as opposed to usings linked CSS style sheets.  The reason for that is if a user happens to view the message when not connected to the internet, then a linked style sheet wouldn't work.  

I've found it to be much easier to create the HTML document in a web page editor, e.g. FrontPage or DreamWeaver, and read the entire page in rather than put all the HTML code in the script.
0
 
LVL 13

Accepted Solution

by:
Mark_FreeSoftware earned 85 total points
ID: 18869371

this is also an example how you can include css in your page:

<HTML><H2>My HTML page.</H2><BODY style="color:#FF0000; font-weight:bold;">My body.</BODY></HTML>
0
 

Author Comment

by:LT1415
ID: 18869791
Thanks. Can I amend my question to ask about how would one embed an image, like a logo?
If you are using VBA inside of an Access form I'm not clear how this is accomplished.
Where does the image reside?

Also in reading some posts on the internet it looks like Outlook 2007 is a nightmare for css users, so it's back to tables and font tags
http://joe.hardy.id.au/blog/2006/11/21/broken-html-rendering-in-outlook-2007/
0
 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 165 total points
ID: 18873660
Adding an image to an HTML message is no different than adding an image to any HTML document.  Simply insert an IMG tag.  To embed the image instead of linking to it follow the steps outlined in this article: http://www.outlookcode.com/d/code/htmlimg.htm
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

679 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