+ Reply to Thread
Results 1 to 12 of 12

Check date, auto email

Hybrid View

  1. #1
    Registered User
    Join Date
    08-06-2013
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    72

    Check date, auto email

    Hiya,

    So every 30 days we have to complete a set of tasks. People are checking the spreadsheet each day for each task to see if the 30 days has come yet (there are maybe 500 rows of data). This makes no sense. It's time consuming, but with the way the tasks are scheduled and set up, we can't use a calendar etc. (too much to get into).

    So I'm looking to:

    1. Have a macro scroll through a list of dates in column H
    2. Once it has determined one (or any) of the dates has hit the 29 day mark, send an email
    3. Have information from column A and B in the body of the email (they'll need to know the details of the task)

    Is this too much to expect from a macro? Would I need to run the macro myself, or could I have it auto run each morning (I'd prefer the auto run, so it'll do it on the weekend when I'm not around too).

    I appreciate any and all help!

    J

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Check date, auto email

    Once the email is sent is the date changed?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    08-06-2013
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    72

    Re: Check date, auto email

    Excellent question. Sorry I forgot to mention that. No, since the user will need to go in and perform the task, the date doesn't need to be updated in Column H (I'd prefer it wasn't until someone performs an action). Thanks!

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Check date, auto email

    So do you want an additional email sent everyday for items that are 29+?

  5. #5
    Registered User
    Join Date
    08-06-2013
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    72

    Re: Check date, auto email

    I'd like to say no, since I think enough people would be copied on the first one, but I think it'll be harder to keep it from doing that since the macro would be scrolling through the dates each and every day (and picking up on the same ones over and over again).

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Check date, auto email

    Where will the email addresses come from?

    e/ Are you using outlook?
    Last edited by Solus Rankin; 08-12-2013 at 10:06 AM. Reason: needed further info

  7. #7
    Registered User
    Join Date
    08-06-2013
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    72

    Re: Check date, auto email

    Sorry (again), yes it will be from (and to) outlook email addresses.

  8. #8
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Check date, auto email

    Are the email addresses in a column? Will it always be the same addresses?

  9. #9
    Registered User
    Join Date
    08-06-2013
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    72

    Re: Check date, auto email

    The email addresses aren't located anywhere in the spreadsheet, but they'll always be the same. There will probably be five people on the distro (To) list. I can add the addresses into the macro in the appropriate section etc.

  10. #10
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Check date, auto email

    Copy this to your workbook module
    Private Sub Workbook_Open()
    
        Application.OnTime TimeValue("08:00:00"), "SomethingElse"
    
    End Sub
    And copy this to its own module:
    Public rngEmail As Range
    
    Public Sub SomethingElse()
    
    Dim l As Long
    Dim lRow As Long
    
    lRow = Range("H" & Rows.Count).End(xlUp).Row
    
    For l = 1 To lRow
        If DateAdd("d", 29, Range("H" & l).Value) = Date Then
            Set rngEmail = Range("A" & l & ":B" & l)
            Call SendEmail
        End If
    Next l
    
    End Sub
    Sub SendEmail()
     
        Dim rng As Range
        Dim OutApp As Object
        Dim OutMail As Object
        With Application
            .EnableEvents = False
            .ScreenUpdating = False
        End With
     
        Set rng = Nothing
        Set rng = rngEmail
    
    
        Set OutApp = CreateObject("Outlook.Application")
        Set OutMail = OutApp.CreateItem(0)
     
        On Error Resume Next
        With OutMail
            .To = "JohnDoe@myemail.com"
            .CC = ""
            .BCC = ""
            .Subject = "This is the status of your tasks"
            .HTMLBody = RangetoHTML(rng)
            '.Send
            .display 'remove ' to display instead of send
        End With
        On Error GoTo 0
     
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
     
        Set OutMail = Nothing
        Set OutApp = Nothing
        
    
    End Sub
    
    Function RangetoHTML(rng As Range)
    
        Dim fso As Object
        Dim ts As Object
        Dim TempFile As String
        Dim TempWB As Workbook
    
        TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
     
        rng.Copy
        Set TempWB = Workbooks.Add(1)
        With TempWB.Sheets(1)
            .Cells(1).PasteSpecial Paste:=8
            .Cells(1).PasteSpecial xlPasteValues, , False, False
            .Cells(1).PasteSpecial xlPasteFormats, , False, False
            .Cells(1).Select
            Application.CutCopyMode = False
            On Error Resume Next
            .DrawingObjects.Visible = True
            .DrawingObjects.Delete
            On Error GoTo 0
        End With
     
        With TempWB.PublishObjects.Add( _
             SourceType:=xlSourceRange, _
             Filename:=TempFile, _
             Sheet:=TempWB.Sheets(1).Name, _
             Source:=TempWB.Sheets(1).UsedRange.Address, _
             HtmlType:=xlHtmlStatic)
            .Publish (True)
        End With
     
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
        RangetoHTML = ts.ReadAll
        ts.Close
        RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                              "align=left x:publishsource=")
     
        TempWB.Close savechanges:=False
        Kill TempFile
     
        Set ts = Nothing
        Set fso = Nothing
        Set TempWB = Nothing
    End Function
    This will run on the ACTIVE SHEET at 8 AM on every day that the workbook is open. The workbook has to be open for this macro to function.

  11. #11
    Registered User
    Join Date
    08-06-2013
    Location
    Pennsylvania
    MS-Off Ver
    Excel 2003
    Posts
    72

    Re: Check date, auto email

    Thanks, I'll give this a try and report back. I appreciate all your help.

    Question: I (or someone else) can open the spreadsheet to kick off the macro, but is there a way to have it run without opening it or is this the only way? It's still helpful either way, I'm just curious. Thanks again.

  12. #12
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Check date, auto email

    It has to be open. There isn't anyway to run a macro in a spreadsheet that isn't open.

    Even if you put the macro in a personal.XLSB an instance of Excel would still have to be open.

+ 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. auto email date coming due
    By bfredricksen in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-18-2013, 11:46 AM
  2. open workbook - check date - send email
    By fabrecass in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-24-2013, 05:07 AM
  3. Auto email notifications activated by cell date
    By ronofcam in forum Excel General
    Replies: 1
    Last Post: 07-24-2012, 10:00 AM
  4. auto sending email before due date via excel 2003
    By AsifShabbir in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 03-02-2011, 09:00 AM
  5. [SOLVED] Can Excel auto-send an email on a given date?
    By dannykray_z in forum Excel General
    Replies: 1
    Last Post: 04-18-2006, 02:43 PM

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