+ Reply to Thread
Results 1 to 23 of 23

Excel/VBA email notification

Hybrid View

warren0127 Excel/VBA email notification 12-29-2009, 02:55 PM
Leith Ross Re: Excel/VBA email... 12-29-2009, 04:09 PM
warren0127 Re: Excel/VBA email... 12-29-2009, 04:26 PM
Leith Ross Re: Excel/VBA email... 12-29-2009, 06:40 PM
warren0127 Re: Excel/VBA email... 12-29-2009, 07:12 PM
arlu1201 Re: Excel/VBA email... 07-26-2012, 06:59 AM
arlu1201 Re: Excel/VBA email... 10-10-2013, 01:02 AM
jorgesoto Re: Excel/VBA email... 05-29-2014, 10:36 AM
  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):


    
    Sub Mail_small_Text_Outlook()
    'Working in Office 2000-2007
        Dim OutApp As Object
        Dim OutMail As Object
        Dim strbody As String
        
        Set OutApp = CreateObject("Outlook.Application")
        OutApp.Session.Logon
        Set OutMail = OutApp.CreateItem(0)
    
        strbody = "Hi there" & vbNewLine & vbNewLine & _
                  "This is line 1" & vbNewLine & _
                  "This is line 2" & vbNewLine & _
                  "This is line 3" & vbNewLine & _
                  "This is line 4"
    
        On Error Resume Next
        With OutMail
            .To = "my email"
            .CC = "someone elses email"
            .BCC = "someone elses email"
            .Subject = "AUTOMATIC EXPIRATION NOTIFICATION"
            .Body = "This is an automated message generated to notify of something about to expire"
            'You can add a file like this
            '.Attachments.Add ("C:\test.txt")
            .Send   'or use .Display
            
        End With
        On Error GoTo 0
    
        Set OutMail = Nothing
        Set OutApp = Nothing
    End Sub
    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,259

    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,259

    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,259

    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
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    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]

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

    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.

  9. #9
    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

+ 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