+ Reply to Thread
Results 1 to 9 of 9

Sending Outlook Emails from/using Excel VBA - Outlook and Excel

  1. #1
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Question Sending Outlook Emails from/using Excel VBA - Outlook and Excel

    Dear Excel VBA experts,

    I have a problem and hopefully you could help me out here. I have also attached an excel file for scenarios, as well as my desired outcome.

    What I wanted on the final outcome is to have emails that I have created in Excel, to be sent out to the respective addresses (to, cc and/or bcc), along with the message and the signature.

    In the attached example, there should be a total of 3 emails to be sent out (assuming that "to", "cc" and "bcc" are included as 1 email, as the content of the body is the same).

    For example, in scenario 1, there should be 3 email addresses in the "to" and "cc" fields and 1 email address in the "bcc" field. With the message of the header (Excel Cell Range A1 to D1) in Excel as well as how it is shown in Excel of Cell Range A2 to D2, and finally the signature.

    In scenario 2, 1 email address in the "to", "cc" and "bcc" field with header (Excel Cell Range A1 to D1) as well as Excel Cell Range A3 to D7, and the signature at the bottom.

    In scenario 3, only 1 address in the "to" field, with header (Excel Cell Range A1 to D1) and Excel Cell Range A8 to D9, and the signature at the bottom.

    So basically, column F is the "criteria" to check how many "lines" of data to input on the body before it decides to create a new email to send.

    I hope that with my attachment and a little of explanation here, you understand completely what I desire to achieve.

    Your help is deeply appreciated in making my work life easier!!!
    Attached Files Attached Files
    Last edited by dluhut; 02-27-2012 at 06:52 PM.

  2. #2
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Sending Outlook Emails from/using Excel VBA - Outlook and Excel

    I have written some code based on your posted workbook example - if the workbook is set up this way then the following code should work. It will calculate what data to attach to each email based on how your example workbook it setup. I have set up the code to Display the email - all you need to do is comment this out and uncomment the .send - if you have code set to send then the email will be sent automatically so I will leave this to you to decide - it is commented in the code as follows. I have attached an example workbook with the code so make sure it works to your specifications. I would recommend when you use this on real data that you leave the code to Display only just until the code has been tested to your satisfaction that the correct data is being placed into the email. You can change the various attributes such as the signature and leading comment in the body of the email - this again has been commented in the code so modify it to your needs. If you need any help then post back.
    I have placed a button on the worksheet to run the code. There is error handling in the code so if there are any errors then please make sure you record the entire error when posting back or do a screen dump.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by smuzoen; 02-25-2012 at 07:43 AM.
    Hope this helps.
    Anthony
    Pack my box with five dozen liquor jugs
    PS: Remember to mark your questions as Solved once you are satisfied. Please rate the answer(s) by selecting the Star in the lower left next to the Triangle. It is appreciated?

  3. #3
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Sending Outlook Emails from/using Excel VBA - Outlook and Excel

    Smuzoen!!! Thank you for your help! It is indeed what I want. I'll study the code so that I can try to change around, especially the signature. Again, thank you! Also, I've added your reputation.

  4. #4
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Sending Outlook Emails from/using Excel VBA - Outlook and Excel

    Fantastic - if you need any help just ask and thank you for the reps. Much appreciated

  5. #5
    Valued Forum Contributor
    Join Date
    04-13-2011
    Location
    Ottawa, Canada
    MS-Off Ver
    365
    Posts
    1,067

    Re: Sending Outlook Emails from/using Excel VBA - Outlook and Excel

    Hi Smuzoen,

    Just wondering if you could teach me a little how to modify the "signature" in a sense that I want the font to be a little smaller , italics, arial format etc.

  6. #6
    Valued Forum Contributor smuzoen's Avatar
    Join Date
    10-28-2011
    Location
    Brisbane, Australia
    MS-Off Ver
    Excel 2003/2007/2010
    Posts
    610

    Re: Sending Outlook Emails from/using Excel VBA - Outlook and Excel

    You would need to send the body as HTML and you can do this using html tags however you need to use the .htmlbody parameter and not .body. If you attach a word document with the signature exactly how you want I will write some html code to add for the signature. If you know html then have a look at http://www.excelforum.com/excel-prog...mail-body.html
    If it is easier just attach a word document with the signature layout and I will write the html to add to the macro

  7. #7
    Registered User
    Join Date
    12-08-2010
    Location
    Mumbai
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Sending Outlook Emails from/using Excel VBA - Outlook and Excel

    Quote Originally Posted by smuzoen View Post
    You would need to send the body as HTML and you can do this using html tags however you need to use the .htmlbody parameter and not .body. If you attach a word document with the signature exactly how you want I will write some html code to add for the signature. If you know html then have a look at http://www.excelforum.com/excel-prog...mail-body.html
    If it is easier just attach a word document with the signature layout and I will write the html to add to the macro
    Hi Smuzoen,

    Was reading your post on Auto generating Emails. I need a Help on the same line.

    Need a help from you, Please.
    In the Macro should only pick those lines who's "Forcasted Deliveries Start Date" in column G is less than todays date and "Balance Qty" in Column I has some value (more than Zero).
    I am referencing the attached file

    Your help in this would be highly appreciated.

    Thanks,
    Chetan
    Attached Files Attached Files
    Last edited by chetanBhavsar; 07-16-2012 at 08:46 AM. Reason: missed to mention the attached file

  8. #8
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Sending Outlook Emails from/using Excel VBA - Outlook and Excel

    Chetan,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  9. #9
    Registered User
    Join Date
    02-19-2013
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Sending Outlook Emails from/using Excel VBA - Outlook and Excel

    Hello everyone,
    New to this forum. I have been looking at the email sending coding. This is very nicely done. What I have been trying to do is similar and yet different. What I need is a macro that will respond to a yes or no in a column then copy a worksheet to another adding the fields to email. I'm not sure if I can used some of the code. Please let me know if this makes sense to you or not.
    Please see new thread.
    Last edited by colinmstone; 02-19-2013 at 03:34 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1