I am attempting to automate an Outlook email creation from within Excel.
I'm using Outlook 2016 and Excel 2016. I have a spreadsheet that the end user adds rows to, and flags the row to be emailed with a Yes/No value.
I want the rows of data to be in a monospaced font, such as courier or Lucida Sans Typewriter, so they line up in their columns properly. But no matter what I try, I cannot seem to automatically accomplish this.
I've tried to use the .BodyFormat = olFormatPlain, thinking this would set the format to plain text, and use the Courier font. Nope - about all this seems to do is remove my ability to change the font before the email is sent out manually.
I've tried to use the .HTMLBody command:
where 'hdr' is the opening line of the email body, "Hi there BOB," or something like that. 'intro' is an opening sentence, along the lines of 'Please place an order for the following parts: '
'rtitem' is a list of data, formatted in a 100 character string per line, with the Sales Order# in position 1 thru 10, the part number in positions 11 thru 25, a description in positions 26 thru 65, the quantity in position 66 thru 75, and a branch id in position 76 thru 85.
When I look at the value of 'rtitem' in the immediate window in Excel, I see this:
Looks perfect!
But when it ends up in Outlook, the font is not Outlook, it is still a proportional font, so it doesn't retain the correct spacing.
Since our IT department has disabled the ability to automatically send an email, my script creates a new Outlook object, builds the contents, and then the user has to manually click on the 'send' button to have it actually go out. Since this is a once a day process, that is not too much to ask of them. So currently, they have to go into the email, highlight the pseudo table, and then change the font to either Courier New or Lucida Sans Typewriter... Then it all lines up great, and they can send the email off.
Any thoughts or suggestions would be greatly appreciated!
Thanks
Steve
I'm using Outlook 2016 and Excel 2016. I have a spreadsheet that the end user adds rows to, and flags the row to be emailed with a Yes/No value.
I want the rows of data to be in a monospaced font, such as courier or Lucida Sans Typewriter, so they line up in their columns properly. But no matter what I try, I cannot seem to automatically accomplish this.
I've tried to use the .BodyFormat = olFormatPlain, thinking this would set the format to plain text, and use the Courier font. Nope - about all this seems to do is remove my ability to change the font before the email is sent out manually.
I've tried to use the .HTMLBody command:
HTML:
.HTMLBody = "<P STYLE='font family=Courier><Font-size=8pt'>" ' & hdr & vbCrLf & intro & vbCrLf & rtitem & vbCrLf & trailer & "</html>"
'rtitem' is a list of data, formatted in a 100 character string per line, with the Sales Order# in position 1 thru 10, the part number in positions 11 thru 25, a description in positions 26 thru 65, the quantity in position 66 thru 75, and a branch id in position 76 thru 85.
When I look at the value of 'rtitem' in the immediate window in Excel, I see this:
Code:
[FONT=Courier New]? rtitem
1907321 21590501 SKID PAD,CARBIDE,WLDMT 2 STC001
1907321 2158940W TUBE, ADJUSTABLE 2 STC001
1907114 2159050W SKID PAD WELDMENT 1 STC001
1906852 3738488 SWITCH,AIR TEMP,90F NC 1 STC001
1906852 1947890 VISOR,SUN 49.72 1 STC001
1906886 7HB192 TURN SIGNAL SWITCH 1 STC001 [/FONT]
But when it ends up in Outlook, the font is not Outlook, it is still a proportional font, so it doesn't retain the correct spacing.
Code:
[FONT=Tahoma]
1907321 21590501 SKID PAD,CARBIDE,WLDMT 2 STC001
1907321 2158940W TUBE, ADJUSTABLE 2 STC001
1907114 2159050W SKID PAD WELDMENT 1 STC001
1906852 3738488 SWITCH,AIR TEMP,90F NC 1 STC001
1906852 1947890 VISOR,SUN 49.72 1 STC001
1906886 7HB192 TURN SIGNAL SWITCH 1 STC001
[/FONT]
Any thoughts or suggestions would be greatly appreciated!
Thanks
Steve