Help with formatting an email with Excel VBA in RTF/html

roscoe

Well-known Member
Joined
Jun 4, 2002
Messages
1,046
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I previously built Excel 2007 code to construct the body of an Outlook email in basic text format (I wasn't skilled enough to do anything fancier in html or RTF format). It polls each line and if it needs to be in the email it pulls out three cells and creates a row in the body of the email. The previous code vertically aligned the data in the email by padding spaces between the data to make it appear to be in a table; however due to the way Outlook 2010 handles text-formatted email (by defaulting now to a proportionally spaced font) this won't work anymore.

What I need is a better way to vertically align the data in a table-like format that doesn't really on font type and spaces. I assume I need to switch to an HTML or RTF email (RTF is preferred if possible). I'm struggling finding any useful help on line.

Can anyone provide me tips (or links) that would help me?

Thanks in advance!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi,

Probably the best starting point for Excel and Outlook is Ron de Bruin's site: Excel Automation - Ron de Bruin Go to Win Tips then select Mail/PDF.

However, adding html into an email is not particularly hard. You just need to add the extra tags to the text you want to send. Perhaps if you start here: HTML Tables and see how to create a table in html.

If you try something out it is probably easier to start with notepad and rename the file from .txt to .html. Then if you double click it it will be displayed in your browser. When that works you can think how to make Excel insert that data into the email body.

Warning: If you try and post html here it will be all messed up because the website will interpret all that html for you. This can be helpful: Free Online XML Escape Tool - FreeFormatter.com
 
Upvote 0
This is me taking my own advice :)

Here is the code from the w3 website ( HTML Tables ) pasted straight in:
Code:
 <table style="width:100%">
  <tr>
    <td>Jill</td>
    <td>Smith</td> 
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td> 
    <td>94</td>
  </tr>
</table>

Code:
<table style="width:100%">
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
</table>










As you can see, the html code from the w3 website has been turned into its final form. This is how it would appear in the email.
The second block of code has been reformatted so that when it is processed as html it looks like the original code. You can make use of that when you need to post html code here, for instance.
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,635
Members
449,043
Latest member
farhansadik

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top