+ Reply to Thread
Results 1 to 23 of 23

Excel/VBA email notification

  1. #1
    Registered User
    Join Date
    12-29-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Excel/VBA email notification

    Hello all,

    I am fairly good at using Excel, but my VBA skills are pretty bad. Here is what I am trying to accomplish (I hope excel can allow me to do this):

    I need to know when something will expire ahead of time. I have certain dates located in cells that an item will expire, for example, a product life of "10-Jul-06 - 11-Aug-09"

    What I am trying to do is have an automatic e-Mail sent out "3 months ahead" of the time something will expire. So in this case, for the above example in August of 2009, I need an email trigger sent out in "May" stating that the item is about to expire. Sort of like an "alert".

    I found some code that will allow me to run a macro which triggers an email. It works, but I need to have it automatically do it when I hit a certain date..not do it "manually" like when you run a macro back on the excel sheet.

    Ultimately, I need an email sent out as soon as a certain day/month comes that will trigger an email message through Microsoft Outlook.


    My Code so far (in VBA module):


    Please Login or Register  to view this content.
    This is not what I want. If someone could please help me find a way to my solution, I would greatly appreciate it. I know there needs to be "IFs" in this, but I could not figure it out.

    Maybe something like "IF Date=March,20,2010, SEND EMAILs" ??

    Thank you so much!

    Warren

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Excel/VBA email notification

    Hello warren0127,

    Welcome to the Forum!

    It would help to know which columns these dates are in and the name of the worksheet they are on. Do you also have a column that is used to mark the email has having been sent?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    12-29-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Excel/VBA email notification

    Hi Leith,

    Thanks and I am glad to be registered!


    Well, I have the expiration dates set which are in columns D34 (the month the product will expire).

    For example, my spreadsheet looks something like this:

    Date From Date To
    D33 column D34 column


    So it would be:

    Date From Date To
    23-Apr-09 22-Apr-10



    I want to add a "3 month ahead of time" column so we know in advance when something will expire, so in this case I would make a separate column with the month of January in it (3 month notice)

    The name of the worksheet tab is "0968" which is sheet #5.

    I currently do not have a column where the email is marked to be sent.

    Is this what you meant?

    EDIT: Attached is an example spreadsheet. Items in Red are the dates, and the sent out date would be the date id like it to trigger to.

    Thanks,

    Warren
    Attached Files Attached Files
    Last edited by warren0127; 12-29-2009 at 04:32 PM. Reason: Attachment

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Excel/VBA email notification

    Hello warren0127,

    Thanks for the example workbook. I don't see a column for email addresses. What do you want as the email subject line and body? What is the column "Send Out Date"? Does it have anything to do with the email?

  5. #5
    Registered User
    Join Date
    12-29-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Excel/VBA email notification

    Hi again,

    I was used to using the old code which didnt do what I wanted, thats why I left the email addresses out. But now I see your point on why there should be a column.

    Attached is the modified spreadsheet containing example e-mail addresses with the designated columns.

    The "send out" date column is the date I want the program to trigger. So, for this case, as soon as "January 10th, 2010" comes around, I would like the program to automatically email all three addresses giving a warning the product is going to expire in April 22, 2010.

    Does this make more sense? sorry for leaving some of these things out..


    Thanks again, looking forward to your responses!!
    Attached Files Attached Files

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Excel/VBA email notification

    Hello Warren0127,

    Thanks for the explanation. I should have told you I do not have Excel 2007. The workbook will need to be in 2003 format before I can look at it.

  7. #7
    Registered User
    Join Date
    12-29-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Excel/VBA email notification

    Hi,

    No problem. I have the updated 2003 attached.

    Thanks,

    Warren
    Attached Files Attached Files

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Excel/VBA email notification

    Hello Warren0127,

    Thanks for the 2003 version. I was thinking to signal that the email has been sent, the font color could be changed from red to some other color like green. What do you think?

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Excel/VBA email notification

    Hello Warren0127,

    I have added the macro shown here to the attached workbook which will run when the workbook opens.
    Please Login or Register  to view this content.
    ThisWorkbook Event Code
    Remove the comment indicator (single quote) and save the workbook if you want the macro to run when the workbook is opened.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    12-29-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Excel/VBA email notification

    Leith,

    I cannot say how much I appreciate you helping me with this. Thank you very much, I will try to run this when I get back into work and I will let you know how it goes!

    Thanks again!!

    Also, can you explain to me what you have done in this code logically? I do not understand excel coding.. like for example, how did you make it trigger the dates, etc?

    Warren
    Last edited by warren0127; 12-29-2009 at 08:31 PM.

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Excel/VBA email notification

    Hello Warren,

    Refer to the code below. The macro determines the area it will be scanning for dates by starting with cell "A5". The range is expanded to include the next 9 columns to the right using the Resize method. The last cell with data in column "A" is found by starting at the bottom of the worksheet. The first non empty cell found marks the end of the data. The row of the end of the range is not allowed to be less than the row of starting cell. This code is more complex than other versions for sizing a range, but it is easier to modify (only the starting cell has to changed) and safer since it will not overwrite any data before the starting cell's row.
    Please Login or Register  to view this content.
    The loop checks the "Date To" (column 4) against today's date + 90. If the dates are equal or "Date To" is greater than today + 90 days and the email has not been sent yet (cell in column "J" of the same row as "Date To" is empty) then send the notice.
    Please Login or Register  to view this content.
    Once the notice has been sent, column "J" of the same row as "Date To" is stamped with today's date.
    Please Login or Register  to view this content.
    I found a few typos in the macro and have corrected them. So use the workbook I have attached to this post. Here is the updated code.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    12-29-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Excel/VBA email notification

    Interesting. I do have a question though..

    Lets say the send date column is the day the emails should be sent out automatically.. Can it somehow be coded to just read that date, and when the day turns out to be the day of the send date, it would automatically send the dates out?

    For example..

    I have the "Send date column" "02-Jan-2010"

    Can that workbook be coded to automatically send the emails out when 02-Jan-2010 arrives? (Date triggers the email)

    Thanks,

    Dave

    Btw I appreciate this because I am learning

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Excel/VBA email notification

    Hello Dave,

    You could use the "Send Date" column to hold the date you want the email to be sent out on. You would still need to flag that the email had been sent. The current code eliminates either adding another column or having to change font color to indicate the email was sent and still sends it 90 days ahead of expiration.

  14. #14
    Registered User
    Join Date
    12-29-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Excel/VBA email notification

    I understand, and thanks.

    I tried testing the code by changing the date and reopening/closing and i didnt receive a test email. This is an automatic code, correct? Do I need to run this manually (Like clicking the Macro button and click "run")?

    I may have to send you my actual working copy (should have done that before).

    Thanks again

    Warren

  15. #15
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Excel/VBA email notification

    Hello Warren0127,

    I have tested this version of the macro and it is working. Be sure you have a date that is is at least 90 days from today's date or the email won't be sent.
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    12-29-2009
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Excel/VBA email notification

    Hi Leith,

    Ok, I will try it when I get back today. I changed the "A5" cell in the code to "A34" because that is where my dates are in the spreadsheet. Everything else remains the same (column #'s etc) and match the code still.

    Changing from A5 to A34 shouldnt cause any problems as long as it has equivalent locations, correct?

    Thanks and I will let you know how my progress is going.

    Warren.

  17. #17
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Excel/VBA email notification

    Hello Warrren0127,

    Changing the starting the starting cell from A5 to A34 won't cause a problem since the starting cell is in the same column and all the columns and formats are the same.

  18. #18
    Registered User
    Join Date
    07-26-2012
    Location
    North Wales
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Excel/VBA email notification

    This thread has been a huge help to me, I hope you don't mind me posting here. I have a similar database and have used this as an example. I've tried to change the code to suit the needs of my database, however it doesn't seem to be working.

    I have a database with statutory and mandatory training that all staff must complete. I have a column to identify the date they completed the training course, and next to that I have a column with a date when the course is next due.

    Here is the code I have currently:

    Please Login or Register  to view this content.
    I have also attached the database. At the minute I am only working on "Sheet 1" and the first 'due date' column even though there are several sheets and several columns, the idea is to have it on them all, but first it has work! Also each 'due date' column is designated to a different member of staff, would I need to have a different code for every person, indicating a different email address? If so, do I just put it under the above code?

    Thanks in advance.

    Jess
    Attached Files Attached Files
    Last edited by arlu1201; 07-26-2012 at 06:59 AM.

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

    Re: Excel/VBA email notification

    Jess,

    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.

    Also,

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature.
    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]

  20. #20
    Registered User
    Join Date
    10-09-2013
    Location
    bangalore
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: Excel/VBA email notification

    Helo,

    I am learning excel and need help to setup alert similar way but little bit different. We need to setup website cert expiration alert notification send to my email address with 3 alerts (90 days before expiration, 60 days before expiration and 30 days before expiration)

    domain.com cert which will expire on 30/01/2014 It should automaticatlly send alert 90 days before one email notification which contain the entire ROW details domain name date of expiration and 2nd alert on 60 days and 3rd alert on 30 days to [email protected]

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

    Re: Excel/VBA email notification

    mmshai1,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.

  22. #22
    Registered User
    Join Date
    05-29-2014
    Posts
    1

    Re: Excel/VBA email notification

    Hello, I'm new to all of this, and I just registered on this site. I know this is an old thread by I'm hoping I can still get a response on this. I've tested this Macro and it seems to work except that instead of sending the email it just opens my web browser. Any idea why it would do that? I'm using excel 2007 on windows 8.1.

    Thanks in advance,

    Jorge

  23. #23
    Registered User
    Join Date
    06-09-2014
    Posts
    1

    Re: Hi,

    I too need to set up an auto notification mail but I need it to be sent on and after the due dates. A mail should be sent on due date (if current date is due date) saying that action item will be past due and again it will be sent after due date saying action item is pass due. I have attached the sheet.

    Note: Owners of action may be multiple and action items can vary. Book1.xlsm

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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