+ Reply to Thread
Results 1 to 32 of 32

Auto Send Email when text value changes from web query

  1. #1
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Auto Send Email when text value changes from web query

    I have this spreadsheet which I am updating on a daily basis. The Formula in 'J2' updates based on the arrival time 'C2' to either "early" or "late" or "on time". But Is there a way to send an email to multiple sources when the value say changes to "late"?.The Whole Row needs to be copied and sent out in an attachment.
    I have seen this macro around by Ron De Bruin but I cant seem to customize this to my sheet.
    Attached Files Attached Files
    Last edited by sonny.thind; 09-10-2011 at 10:50 AM.

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Auto Send Email when text value changes from web query

    Hi,

    You insert this into the Sheet code (Not a module)

    Code:

    Please Login or Register  to view this content.
    Steffen Thomsen

  3. #3
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Re: Auto Send Email when text value changes from web query

    will this Mail code work? so where do I add the "Cell.EntireRow"?



    Please Login or Register  to view this content.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Send Email when text value changes from web query

    Hi sonny.thind

    Please include in the workbook the code you've tried. We'll look at it and see if we can make it work.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Auto Send Email when text value changes from web query

    Try this:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Re: Auto Send Email when text value changes from web query

    still not working ! Not sure If I am doing anything wrong here, ( I have attached the sheet I am working this on)

    so the email address would be on sheet 2 , So if column"J" is "late" then it will copy the whole row and send an email to the addresses listed on sheet 2 and list them on sheet 2 as they come in.
    Please note that this worksheet is a web query which refreshed every 20mins for updates.
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Re: Auto Send Email when text value changes from web query

    Quote Originally Posted by sonny.thind View Post
    still not working ! Not sure If I am doing anything wrong here, ( I have attached the sheet I am working this on)

    so the email address would be on sheet 2 , So if column"J" is "late" then it will copy the whole row and send an email to the addresses listed on sheet 2 and list them on sheet 2 as they come in.
    Please note that this worksheet is a web query which refreshed every 20mins for updates.
    the code works fine to draft the email if I change .Body = Cell.EntireRow to .Body = EntireRow but doesn't copy the row

    Please Login or Register  to view this content.

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Send Email when text value changes from web query

    Hi sonny.thind

    Try the code in the attached. Works when one line is updated. Don't know what will happen if more that one line gets updated...try it and find out...let me know.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Re: Auto Send Email when text value changes from web query

    Yes it works as it keeps on displaying a new email every time. Ill try and tweak it a bit to see if I require any additional help with this.
    Thanks for your help though.

  10. #10
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Re: Auto Send Email when text value changes from web query

    Hi John,
    So what if I need to have the copied row (which is "late") also copied onto another sheet for a report or and add it to a template so that I can then copy the whole template to draft a proper email .

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Send Email when text value changes from web query

    Hi sonny.thind

    This is relatively simple (I think )
    what if I need to have the copied row (which is "late") also copied onto another sheet
    What I'm not sure of is this
    add it to a template so that I can then copy the whole template to draft a proper email
    What's "a proper email" look like. I'm assuming you don't want 50 emails going out if 50 items change to "Late". I'd assume you want one email that includes all 50 items. Please confirm if my assumptions are correct (or not).

    Additionally you have 17 columns of data. So what's the "proper email" going to look like? Getting 17 columns of data into the body of an email may be problematic. It can be done but will it be readable?

    Mock up a worksheet that demonstrates what you expect to see in the body of the email. We'll see if we can make it happen. An attachment may be more appropriate.

  12. #12
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Smile Re: Auto Send Email when text value changes from web query

    Quote Originally Posted by jaslake View Post
    Hi sonny.thind

    This is relatively simple (I think )

    What I'm not sure of is this

    What's "a proper email" look like. I'm assuming you don't want 50 emails going out if 50 items change to "Late". I'd assume you want one email that includes all 50 items. Please confirm if my assumptions are correct (or not).

    Additionally you have 17 columns of data. So what's the "proper email" going to look like? Getting 17 columns of data into the body of an email may be problematic. It can be done but will it be readable?

    Mock up a worksheet that demonstrates what you expect to see in the body of the email. We'll see if we can make it happen. An attachment may be more appropriate.
    Hi John,

    This actually is a daily delivery report by carriers in various locations that deliver product ,each row being 1 order.So I need to be aware of these delays and notify the desired customer . The current macro works fine as I am importing this from a web query which is set to refresh every hour or 3hrs and I have set the .TO email to myself and I will then forward this to the desired customer (which is a distribution list I create from another macro).
    the email is simple All that is needed in the email would be( Dear Sir/Madam, this order "Column B" was "late (column J") by " how much time Column K" ) which is all there in the Row that is emailed.

    However the idea to copy all the "late" order to another sheet where I can then send the list to everyone in time intervals of 3hr could also be an ideal option.

    [add it to a template so that I can then copy the whole template to draft a proper email
    Sorry about this as I was thinking of a longer email--but I think what I mentioned above would suffice.

  13. #13
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Auto Send Email when text value changes from web query

    Hi,

    Regarding to sending mail using templates then i have had good use of this piece of code.

    Step 1

    Create a html template

    Step 2

    In the template place variables where text need to be inserted

    Step 3

    modify the paths in the code to fit your paths

    Step 4

    Setup your the code with your outgoing smtp

    Heres the code, se if you can modify it to work, the smart thing with this way of sendingmails is that it doesnt use a mailprogram to send the mail but rather connect directly to the outgoing mailserver.

    Please Login or Register  to view this content.
    Be aware that you need to keep the same folder structure or create a new and modify the code

    Steffen Thomsen

  14. #14
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Re: Auto Send Email when text value changes from web query

    Hi
    Couple of issues I am having with this code (please bear with me )

    1) I am using my work Microsoft Exchange server, would that cause any issues?. we have a lot of Firewalls so I would prefer to do this through regular sources
    2) Also I have attached the Email Template -I require only certain columns be sent instead of the entire row. I also need the copied Row onto a second sheet to generate a report.
    3) What if I need to change the statuses i.e change from "Late" and Add maybe some "Early" and some "On Time"

    Say I am using the same Sheet attached ,Could you help modify this with the new parameters I mentioned?

    thanks a bunch
    Attached Files Attached Files
    Last edited by sonny.thind; 08-30-2011 at 10:05 AM. Reason: more info added

  15. #15
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Send Email when text value changes from web query

    Hi sonny.thind

    Don't know to whom you're responding
    Couple of issues I am having with this code (please bear with me )
    You've got a couple of code versions posted...to which code are you referring?

  16. #16
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Re: Auto Send Email when text value changes from web query

    Quote Originally Posted by jaslake View Post
    Hi sonny.thind

    Don't know to whom you're responding

    You've got a couple of code versions posted...to which code are you referring?
    its the one that Steffen posted..

  17. #17
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Send Email when text value changes from web query

    Hi sonny.thind

    In the attached is code that completes an Email template as you described. The code also copies the complete row to Sheet4.

    You will have three attachments:
    BOOks3.3.xlsm
    Email.JPG
    Delivery Notification.txt

    The Email.JPG is a picture of the Email that's generated. The Delivery Notification.txt file is the actual Outlook Template used in the Email. You'll need to rename the file to Delivery Notification.oft.

    Place the workbook and the Outlook Template in the SAME folder.

    I don't know about Microsoft Exchange servers so I can't help you with the question.

    You'll need to expand on this
    What if I need to change the statuses i.e change from "Late" and Add maybe some "Early" and some "On Time"
    ...what is it you wish to do?
    Attached Images Attached Images
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Re: Auto Send Email when text value changes from web query

    Hi John,
    sorry but the .xls sheet is the same one from before.. gives me the original email without the template.. ccan youpleaseverify


    to answer your question
    What if I need to change the statuses i.e change from "Late" and Add maybe some "Early" and some "On Time"
    Time to Time I would want to provide notifications for the Early ones as well.. since if they are supposed to show up within a specific time why are they coming earlier..? is there a way then that I can tweak the code a bit to modify this?

  19. #19
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Send Email when text value changes from web query

    Hi sonny.thind

    Sorry 'but that. See attached
    Attached Files Attached Files

  20. #20
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Re: Auto Send Email when text value changes from web query

    Sorry and Thanks John,

    but I am trying to get this to work.. not sure what is happening though but I keep getting the error (see screen shot) even though I have the delivery notification.oft in the same folder.

    am I doing something wrong or dumb here?
    Attached Files Attached Files

  21. #21
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Send Email when text value changes from web query

    Hi sonny.thind

    Don't know.

    Does the file exist in the path described in the error message?

    Double click on the file itself "Delivery Notification.oft" ...does it open?

    Add these lines of code here and set a break point as described
    Please Login or Register  to view this content.
    Look at the Immediate Window...it should look like this
    Please Login or Register  to view this content.
    Has the code executed to the Break Point? Is this the correct path
    Please Login or Register  to view this content.
    If all is well to this point step through the rest of the code. Let me know what happens.

    PS: set a breakpoinh here also
    Please Login or Register  to view this content.
    Last edited by jaslake; 09-03-2011 at 12:07 PM.

  22. #22
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Send Email when text value changes from web query

    Hi sonny.thind

    Set a breakpoint here also
    Please Login or Register  to view this content.
    Another thing that came to mind...did you
    The Delivery Notification.txt file is the actual Outlook Template used in the Email. You'll need to rename the file to Delivery Notification.oft.
    Last edited by jaslake; 09-03-2011 at 07:49 PM.

  23. #23
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Re: Auto Send Email when text value changes from web query

    Hi John,

    still cant get this to work. I even changed the path to an external drive and the template name and still doesn't work. keep getting the same error.

    can I hard code the file location for the template to Z:\R\Delivery Notification.oft

    also I have attached the delivery notification template like you provided. could there be an issue with this file?
    Attached Files Attached Files

  24. #24
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Send Email when text value changes from web query

    Hi sonny.thind

    Well I'm also unable to open the file...get the same error message you're getting. It must be corrupted.



    We can do one of several thing (or all three):
    1. The Forum won't allow me to attach an .oft file so I'm going to reattach the Delivery Notification.txt which you'll need to rename Delivery Notification.oft.
    2. You can re-download the original Delivery Notification.txt which you'll need to rename Delivery Notification.oft.
    3. I can email you a copy of the original Delivery Notification.oft.
    I tried number 2 successfully. If you opt for number 3, PM me with your email address. Let me know how it goes.
    Attached Files Attached Files

  25. #25
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Re: Auto Send Email when text value changes from web query

    Hi John,

    thanks a lot ,it works now , so it must have had to do with the file.

    but another problem crops up. I am getting a run time error whenever the email is drafted..

    please see attached..
    Attached Files Attached Files
    Last edited by sonny.thind; 09-07-2011 at 02:51 PM. Reason: wrong file attached..

  26. #26
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Send Email when text value changes from web query

    Hi Sonny

    Please comment out this line of code and see if the procedure completes
    Please Login or Register  to view this content.
    The code is in
    Please Login or Register  to view this content.
    Let me know what happens.

  27. #27
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Re: Auto Send Email when text value changes from web query

    yup works now!. ok but the reported "late" doesn't continue to list on sheet 4. they get deleted once the email is sent?. what is the change in the code I need to do on to make this stay on sheet 4 and act as a permanent list?

  28. #28
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Send Email when text value changes from web query

    Hi Sonny

    There's nothing in the code that clears Sheet4...is there NOTHING in Sheet4?

  29. #29
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Re: Auto Send Email when text value changes from web query

    No I meant that , when the order is reported "late" it copies to sheet 4 which is great but when the next one shows up the previous one is deleted and only keeps the latest row that is "late" so it only has 1 order at all times even when there are multiple rows reported 'late' .

  30. #30
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Send Email when text value changes from web query

    Hi Sonny

    Are the Emails displaying properly...one Email per changed row??

  31. #31
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Auto Send Email when text value changes from web query

    Hi Sonny

    Been sittin' here trying to understand this
    keeps the latest row that is "late" so it only has 1 order at all times even when there are multiple rows reported 'late' .
    Trying to understand 'cause this doesn't happen in my environment...it keeps all updated records in Sheet4 so as to
    Please Login or Register  to view this content.
    As I see it, there's only two things that can be causing this. I'm going to keep issue 2 until later...'cause I don't have the current knowledge to fix it. I'm going to deal with issue 1 and hopefully that'll resolve the problem.

    Issue 1:
    The current code assumes that Columns A and B in Sheet1 are populated . In your sample file they were not...so, in my testing, I populated them. I assumed, in the "Real World", they'd be populated...perhaps a bad assumption...perhaps not. Regardless...we're going to change the code such that the code will look at a Column that will ALWAYS be populated...Column C. This comes into play here
    Please Login or Register  to view this content.
    I'd like you to run the code in the attached...see if it resolves the current issue...keep me posted.
    Attached Files Attached Files

  32. #32
    Forum Contributor
    Join Date
    07-04-2011
    Location
    London, Ontario
    MS-Off Ver
    Excel 365
    Posts
    119

    Smile Re: Auto Send Email when text value changes from web query

    Hi John,

    yes it works now.. thanks so much for your help.

    really appreciate all your effort and patience in this..

    thanks again..
    regards

    sonny..

+ 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