+ Reply to Thread
Results 1 to 18 of 18

VBA program to mail a row to multiple people

  1. #1
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Post VBA program to mail a row to multiple people

    Hi,

    I am trying to create a macro that would loop through a set of rows and send emails via outlook. Please see attached Excel workbook for the data I am trying to send.

    Contents of the email

    "To" field: columns I and J of each row in the worksheet "Feb. 2012"
    "CC" field: All of the emails in the range of "CC List" worksheet
    Subject: regular string of text

    Body: Text found in cells A1:A26 of "Template" worksheet AND the header row for the table in "Feb. 2012" AND the row corresponding to the email recipients.

    I would like for the macro to loop through each row and send the email with contents only relevant to the recipient.

    To see an example of the email I want to send please go to "Example Screenshot" Worksheet

    Thank you so much!
    Attached Files Attached Files
    Last edited by g1987; 03-09-2012 at 07:28 PM.

  2. #2
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: VBA program to mail a row to multiple people

    try something like this, it may require a bit of tweaking to fit your sheet

    Please Login or Register  to view this content.
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  3. #3
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VBA program to mail a row to multiple people

    Thanks for you reply.
    Can you please add comments to your code so that I know what you're trying to do?
    I think it's close to what I want but not entirely...

  4. #4
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: VBA program to mail a row to multiple people

    with comments
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VBA program to mail a row to multiple people

    by mistake
    Last edited by g1987; 03-09-2012 at 03:24 PM.

  6. #6
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VBA program to mail a row to multiple people

    Not quite what I'm looking for actually.

    So I've got this code below and it works for the first instance but it fails to loop. I also need to figure out a way to include the header of the table every time. I also need to add the CC recipients somehow and have 2 recipients in the "To" which will (r,11) and (r,12)

    Please Login or Register  to view this content.
    AND

    Please Login or Register  to view this content.

  7. #7
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: VBA program to mail a row to multiple people

    the method in my code is not using the outlook application method, but instead the envlope method. you can add a cc by adding the following line:

    Please Login or Register  to view this content.
    the address could be a variable as well.

    i understand alot of people prefer to use the outlook object method, i have just found this method to be simple and quick. i often have to use it to send custom templates out to 300+ people, so i use it in a loop where part of the loop changes a lookup value, and it has worked flawlessly for me in that scenario.

  8. #8
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VBA program to mail a row to multiple people

    okay. I see what you mean.

    However, how can I make it send the row of the table corresponding to the email recipient (plus the header of the table) along with the "Template" text?

  9. #9
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: VBA program to mail a row to multiple people

    what i do is make the template sheet dynamic, leave your default text, then a vlookup for the second portion of the e-mail. you can set the macro to change a cell outside of the e-mail range to the look up value, then your e-mail body will update. you can then send that. i hope that was clear, I'm not able to write the code right now for you, but if you still need help i can try to do that soon. basicaly you just need to add into the loop something like
    Please Login or Register  to view this content.
    and change the selected range to A1:A3, where A3 is a vlookup formula based on C1.

    Good Luck,

    -Dan

  10. #10
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VBA program to mail a row to multiple people

    yes, please. If you could show me the code that would be great.

    The TO fields are dynamic and based on the rows in the tables. Email Field 1 and Email Field 2 columns
    The CC field is a static list
    The Body contains a static portion (text portion) and the dynamic portion based on the rows of the table.

  11. #11
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VBA program to mail a row to multiple people

    so I have the code for the TO fields and CC fields figured out.

    I need to figure out the Body of the email problem.

    Like I said before, there's static and dynamic portions.

    The table header will always need to be copied over
    The row will depend on in what iteration of "r" we are on.

    thank you!

  12. #12
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: VBA program to mail a row to multiple people

    my code will only send a contigous range of selected cells, so you need to make your template have a set range to send, for example A1:A3, and in A3 have a formula to pull the line that should be sent.

  13. #13
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VBA program to mail a row to multiple people

    that might work actually. When you get a chance please post it.

    Thanks a lot

  14. #14
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VBA program to mail a row to multiple people

    I think I might have it figured out
    I have some other things I need to fix but I'll start another topic or look for the answers. thank you so much

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VBA program to mail a row to multiple people

    Actually, no that doesn't work. It copies over the selection but does not send it in the email...

  16. #16
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VBA program to mail a row to multiple people

    ok silly answer i just needed to extend the range of what it is selecting

    Please Login or Register  to view this content.

  17. #17
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: VBA program to mail a row to multiple people

    glad it worked out for you, let me know if you need more help, ill do what i can.

  18. #18
    Registered User
    Join Date
    03-09-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2007
    Posts
    31

    Re: VBA program to mail a row to multiple people

    If you can help me with this one that would be great

    http://www.excelforum.com/excel-prog...e-sending.html

+ 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