Search code examples
vbaexceloutlook-2010

Using Excel VBa to send Outlook e-mails


I'm developing an Excel macro to send e-mails to specific customers. The code I have so far works pretty well. This is the first macro I've done with Outlook. The issue I'm having is with the DETAIL_INFO variable. The detail info should have 2 columns: (1) for customer information and (2) for invoice information. There will be 4 or 5 fields in each column. What I'm trying to do is have some verbiage at the begging of the e-mail and then display the invoice information in 2 columns. I'd like a separate section for each invoice. There could be 1 invoice or there could be multiple invoices. Once the invoice information is displayed, then there is some additional verbiage.

Can this be done? Below the code is some sample results. Thanks for the help...

strbody = "<font size=""3"" face=""Calibri"">" & _
    Date & "<br><br>" & _
    VarB & " " & VarC & "<br>" & _
    Add1 & "<br>" & _
    Add2 & ", " & Add3 & "    " & Add4 & "<br><br><br>" & _
    "Dear Customer,<br><br>" & _
    "Thank you for choosing us.<br><br>" & _
    "We appreciate your business.  At times, we follow up with customers<br>" & _
    "to minimize confusion.<br><br>" & _
    "Please see below for more details:<br><br><br>" & _
    DETAIL_INFO & "<br>" & _
    "<br><br><br>Our goal is to handle these situations as promptly as possible." & _
   "Again, we appreciate the opportunity to serve you.<br><br>" & _
    "Sincerely,<br>" & _
    "ABC Company"

Results:

blah blah blah

Contact Info Invoice Info First Name: Joe Invoice ID: 12345 Last Name: Smith Invoice Date: 05/15/2015 City: Kansas City Invoice Amt: 15.00 State: MO Due Date: 06/15/2015

Contact Info # 2 Invoice Info # 2 First Name: Bill Invoice ID: 11223 Last Name: Jones Invoice Date: 05/25/2015 City: Kansas City Invoice Amt: 25.00 State: MO Due Date: 06/25/2015

Thanks again for your help.......


Solution

  • Look at Ron de Bruin's site for great ways of creating emails. The linked page shows how to get Excel to do the hard work of turning a range into an HTML email.