+ Reply to Thread
Results 1 to 23 of 23

EXCEL VBA send dynamic emails messages based on trigger column

  1. #1
    Registered User
    Join Date
    04-17-2016
    Location
    St Louis
    MS-Off Ver
    2013
    Posts
    13

    EXCEL VBA send dynamic emails messages based on trigger column

    I am attempting to send emails to a distribution list based on a trigger column (column E). Each row that contains the word "Captured" should send an email to the address in column A. The email body for these outgoing emails should contain content in column D. Ideally I would like the Name (B) and Client (C) to dynamically appear in the Subject of the email.


    The code below, fires to the correct recipients but sends the same message body (last one within the list to all email addresses).

    I am in need of this for a large project so any help would be amazing!
    Please Login or Register  to view this content.
    Last edited by mcjonesy; 04-17-2016 at 09:41 PM.

  2. #2
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    post withdrawn
    Last edited by humdingaling; 04-17-2016 at 09:53 PM. Reason: OP complied
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    04-17-2016
    Location
    St Louis
    MS-Off Ver
    2013
    Posts
    13

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    I have posted my code per your suggestion. Sorry for the mistake.

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    reason why your receipts are dynamic but nothing else is because of this line

    Please Login or Register  to view this content.
    you dont have something similar for your mess or your subject
    to get subject in there you should have a variable to capture subject as well

    how exactly do you want to structure your subject and your "mess"

    ps why are you using
    Please Login or Register  to view this content.
    instead of just
    Please Login or Register  to view this content.
    ?

  5. #5
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    i've reconstructed what i think your spreadsheet looks like and added some sample code of what you could possibly do
    Please Login or Register  to view this content.
    see if you does what you want
    ps i changed .send to .display so it doesnt automatically send out emails while you are debugging
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    04-17-2016
    Location
    St Louis
    MS-Off Ver
    2013
    Posts
    13

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    I used
    Please Login or Register  to view this content.
    because those were the instructions of the tutorial I watched. https://www.youtube.com/watch?v=Em4RCvsAV7s

    I am open to whatever is easiest. This video did not show me how to dynamically set subject and dynamic messages. I would like to send a message when Captured is identified to look like the following.

    Subject "Monsanto (client C) Application Development (b name) Opportunity"

    Message body: "This would be a sentence extracted by whatever was typed into Column D of the related row"







    Email First Last opportunity email
    [email protected] Mike Peters I will be working at express scripts.
    [email protected] John smith I am a excel guru TEST
    [email protected] robyn williams ABI here I come. YUMMY! TEST

  7. #7
    Registered User
    Join Date
    04-17-2016
    Location
    St Louis
    MS-Off Ver
    2013
    Posts
    13

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    this is very close. I tried out your attachment, the only thing is that each email should be sent separately not in one joint email. So in your example there should be 4 separate emails. Any suggestions?

  8. #8
    Registered User
    Join Date
    04-17-2016
    Location
    St Louis
    MS-Off Ver
    2013
    Posts
    13

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    I don't want to make things to complicated but can separate emails can be sent only for unique email addresses? In your example if row three and nine were both [email protected] with two different messages. Is it possible to group those messages in one email (with a blank line in between) while keeping other rows with different email addresses separate?

  9. #9
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    Quote Originally Posted by mcjonesy View Post
    this is very close. I tried out your attachment, the only thing is that each email should be sent separately not in one joint email. So in your example there should be 4 separate emails. Any suggestions?
    yes, essentially
    you put the mailitems (.to,.subject,.body,etc) within the icounter For/Next Loop
    so it generates seperate email per loop

    Quote Originally Posted by mcjonesy View Post
    I don't want to make things to complicated but can separate emails can be sent only for unique email addresses? In your example if row three and nine were both [email protected] with two different messages. Is it possible to group those messages in one email (with a blank line in between) while keeping other rows with different email addresses separate?
    this is slightly more complicated
    i will need to have a little think on how to do this the easiest way

    how many rows of data are you expecting to run this for?
    50, 1000, 1000000?

  10. #10
    Registered User
    Join Date
    04-17-2016
    Location
    St Louis
    MS-Off Ver
    2013
    Posts
    13

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    no more than 100 per email address at once. I will be using code to change the trigger column cell after sending the emails.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    04-17-2016
    Location
    St Louis
    MS-Off Ver
    2013
    Posts
    13

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    no more than 100 per email address at once. I will be using code to change the trigger column cell after sending the emails.

    Please Login or Register  to view this content.

  12. #12
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    you can do capture > sent code at the same time of the email
    no need to run it seperately

    On unique emails
    can i put a helper column in the data to count number of emails to each email address?
    it would save me putting it in the code itself

    also re:subject
    i changed it to Subject = "Monsanto " & Cells(Icounter, 3).Value & " Application Development " & Cells(Icounter, 2).Value & " Opportunity"
    however in the case there are more than one emails, how do you want subject handled?

  13. #13
    Registered User
    Join Date
    04-17-2016
    Location
    St Louis
    MS-Off Ver
    2013
    Posts
    13

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    Yes a helper column would be fine. I can always hide the column when the spreadsheet is being reviewed.

    If more than one message is being sent in an email I suggest the Subject line be hard coded to read "capability Opportunity" and the message body have a table like structure

    Column one Client/ column two would be opportunity name/ column three would be the message specific

    Each row would repeat the format

    I modified your code of where the mailitems (.to,.subject,.body,etc) within the icounter For/Next Loop

    Is this correct?
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    04-17-2016
    Location
    St Louis
    MS-Off Ver
    2013
    Posts
    13

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    Sorry to be a pain but I cannot figure out where within the code the .to, subject, body, send need to go in order to send separate emails. If you can re-paste the code with it in its correct place that would be amazing! humdingaling you have been super helpful!

  15. #15
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    it was a bit more complicated then i thought but no need for helper column since you change "Captured" to "sent"
    Please Login or Register  to view this content.
    few more variables involved mainly with capturing multiple lines into one email
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    04-17-2016
    Location
    St Louis
    MS-Off Ver
    2013
    Posts
    13

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    Two bugs:

    1. the code provided sends an email for each occurrence of an email address regardless the rows conditional trigger if one row is listed as Captured

    2. The body of an email with multiple entries lists all rows messages. Only rows with Captured should be listed in the body of the email.


    Enhancement request:

    Of the grouped mass emails their should be one email for each Client.


    Example:

    Pearl has 4 rows with her email address
    Two of the rows are with Client "ABI" with a to send column as "Captured"
    One row is listed as "Express Scripts" with a to send column as "Captured"
    One Row is listed as "RGA" with a to send column as "Sent"

    Pearl will receive two emails.

    1st email

    Subject: ABI (client name) opportunities

    Body:
    • Opportunity 1
    • Opportunity 2

    2nd Email

    Subject: Express Scripts (client name) Opportunities
    Body:
    • Opportunity 1

    Thank you again for your help. You have been a life saver!

  17. #17
    Registered User
    Join Date
    04-17-2016
    Location
    St Louis
    MS-Off Ver
    2013
    Posts
    13

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    I took your example and modified it slightly. Bug one from above is resolved. Bug two still exists.

    If the enhancement from my post above isn't possible I would like to format the email body with two columns Cap and Mess. A grid would be ideal.

    Thoughts? Also I would be happy to attach my excel project to these posts but it appears I am not able too.

    Please Login or Register  to view this content.
    Last edited by mcjonesy; 04-18-2016 at 05:12 PM.

  18. #18
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    Sorry wasnt able to look at this today
    got bogged down at work

    try these methods for uploading file
    http://www.excelforum.com/the-water-...his-forum.html

  19. #19
    Registered User
    Join Date
    04-17-2016
    Location
    St Louis
    MS-Off Ver
    2013
    Posts
    13

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    Posting Project.

    Reasons it didn't allow me to attach:

    1. Document was open

    2. I was using microsoft Edge browser
    Attached Files Attached Files

  20. #20
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    ok i found the issues in your code

    you didnt update the column references properly on every line

    ie
    Please Login or Register  to view this content.
    should be
    Please Login or Register  to view this content.
    and your rangetosearch wasnt pointing to the right column
    Please Login or Register  to view this content.
    in turn it wasnt updating column 9 properly
    Last edited by humdingaling; 04-20-2016 at 08:54 PM. Reason: Use file attached in post #21

  21. #21
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    so i had a chance to properly review your code
    it seems you had two running variables "cap" and "mess" to change essentially one line of Body
    this seems unnecessary and can lead to confusion so i combined into one

    also got rid of mutliple CountA lines and replaced them with one variable that you calculate once

    Please Login or Register  to view this content.
    attached new file
    hopefully this one works properly now
    Attached Files Attached Files

  22. #22
    Registered User
    Join Date
    04-17-2016
    Location
    St Louis
    MS-Off Ver
    2013
    Posts
    13

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    I submitted my project Friday and everything works great! Thank you so much for your help!

  23. #23
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: EXCEL VBA send dynamic emails messages based on trigger column

    not a problem
    glad to have helped


    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel vba to auto-send customer emails (duplicate emails issue)
    By nadz84 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-29-2015, 10:08 AM
  2. Replies: 2
    Last Post: 12-19-2014, 11:28 AM
  3. Send Emails once expiry date is reached, and generate report based on emails sent
    By demonicscorpion in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2014, 05:36 AM
  4. [SOLVED] Need help getting excel to send automatic emails based on cell value
    By Quito in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-11-2014, 07:09 AM
  5. Automatically send an email based on the value of a cell and/or trigger date
    By psn.arya in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-05-2013, 06:17 PM
  6. Send Emails based on cell value
    By kaki1956 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-22-2010, 08:28 PM
  7. Sending macro emails using excel: Send emails with their passwords.
    By loveisblind in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2009, 03:16 PM

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