Create email body using HTML table

kyndsi

New Member
Joined
Feb 16, 2018
Messages
16
I am using an excel macro to pull data from an external application and generate an Outlook email message with the data that is generated. The macro works well, but the email message output is messy and difficult to align in a presentable fashion.

The macro pulls inventory counts for multiple items, then places them into a 2 column list in an email message. Currently, the columns are aligned using spaces to align the right column, but it is impossible to get a consistent and clean output, as spacing this way is dependent on font type and size on the end user's view.

Therefore, I would like to wrap the output in an HTML table to create a uniform and consistent layout for the email body.

The code that generates the data table is written as follows:

mail.Body = mail.Body & "Item Header Count Header" & Chr(10)
mail.Body = mail.Body & "Item 1 " & intCountArray(1)
mail.Body = mail.Body & "Item 2 " & intCountArray(2)
mail.Body = mail.Body & "Item 3 " & intCountArray(5)
mail.Body = mail.Body & "Item 4 " & intCountArray(3)
mail.Body = mail.Body & "Item 5 " & intCountArray(4)
mail.Body = mail.Body & "Total of Items " & intTotalFiles & Chr(10) & Chr(10)

The code above uses generic list items, actual items are of differing lengths.

I have seen some examples of code that create HTML tables, but none that match the format used in this macro.
 
I finally had a chance to test this at work, and it is not working. Runs with no errors, but none of the html elements are displayed in the email.

I did take all of the spaces out of the html elements, and even tried adding an extra 'sHTMLBody &' where it appears to be missing.
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
OK, had a look back at the thread and realized that I missed the code for the mail body from your first post. Added that, and the script works now. My apologies for that.

However, now that it runs, the HTML table doesn't format properly. It displays with no vertical alignment, like this:

Inventory Item Count
Expired 35
Pending 212
Secondary Note 13
Over 180 Days 10
Docs Received 0
Total of Items 270

Any thoughts?

Thanks again for your time on this.
 
Upvote 0
It will be difficult to help without looking at the actual code that you're using. Can you post your code?
 
Upvote 0
Hi, sorry for the delay. Was away on vacation for a couple of weeks.

I realized later that there are additional text elements included in the email body created by the script that are outside of this particular part of the code. These needed to be converted to HTML and included in a single container for the entire email body output.

The elements that were still initially plain text were interfering with the HTML output for this output table.

Now that I have the entire email body as HTML, everything works well.

Thanks again for your time on this.
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,739
Members
449,050
Latest member
excelknuckles

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