Results 1 to 57 of 57

help with VBA conditional notification emails

Threaded View

  1. #16
    Forum Contributor
    Join Date
    05-02-2013
    Location
    Poland
    MS-Off Ver
    Excel 2013
    Posts
    265

    Re: help with VBA conditional notification emails

    We really just want to check if the send_mail sub is being called, right? You claim that the send_mail sub is not being called. To check this, we write the simplest code. If there is data in column J, it means that the send_mail sub is being called.

    Public k As Long
    ...
    Sub send_mail()
        k = k + 1
        Worksheets("Schedule").Range("J" & k).Value = Format(Now, "yyyy.mm.dd hh:mm")
        
        UpdateClock
    End Sub
    I will provide the file again, but you must ensure:

    1. The file contains only 1 sheet Schedule and my code, without your sheets and codes. Because we will only check my code, right? We do not know what your code does, and whether it does not affect my code. And we only want to check my code.

    2. You cannot change, add, delete anything.

    3. Download the attached file --> run the file --> leave it for a few hours --> see if there is data in column J entered by sub send_mail.

    code in ThisWorkbook
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    On Error Resume Next
        Application.OnTime lastTime, "send_mail", , False
    End Sub
    
    Private Sub Workbook_Open()
        UpdateClock
    End Sub
    code in Module1
    Option Explicit
    
    Public lastTime As Double
    Public k As Long
    
    Private Function readTime()
    Dim day As Long, lastRow As Long, i As Long, curr_time As Double
        curr_time = 0
        day = Weekday(Date)
        With Worksheets("Schedule")
            lastRow = .Cells(Rows.Count, day).End(xlUp).Row
            For i = 2 To lastRow
                If .Cells(i, day).Value > Time Then
                    curr_time = .Cells(i, day).Value
                    Exit For
                End If
            Next i
            If curr_time = 0 Then curr_time = Date + 1 + .Cells(2, (day Mod 7) + 1).Value     
        End With
        readTime = curr_time
    End Function
    
    Sub UpdateClock()
    Dim curr_time As Double
        curr_time = readTime
        If curr_time = 0 Then
            Application.OnTime lastTime, "send_mail", , False
        Else
            lastTime = curr_time
            Application.OnTime lastTime, "send_mail"
        End If
    End Sub
    
    Sub send_mail()
        k = k + 1
        Worksheets("Schedule").Range("J" & k).Value = Format(Now, "yyyy.mm.dd hh:mm")
        
        UpdateClock
    End Sub
    I added in function readTime
    If curr_time = 0 Then curr_time = Date + 1 + .Cells(2, (day Mod 7) + 1).Value
    In the previous readTime the code reaches the last hour and turns off the clock. With the above line the code reaches the last hour then takes the first hour of the next day.
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Not receiving notification emails
    By Sintek in forum Excel General
    Replies: 28
    Last Post: 01-16-2017, 06:51 AM
  2. Can excel send an email notification when a conditional format has taken effect.
    By 2Sassy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-21-2016, 06:34 PM
  3. Deadline notification through conditional formating
    By dimitrioskal in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-16-2014, 06:20 AM
  4. Conditional Formatting on Due dates and email notification
    By dmallory in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-16-2014, 02:55 PM
  5. multiple notification emails
    By Andy Pope in forum Suggestions for Improvement
    Replies: 1
    Last Post: 09-19-2013, 02:18 PM
  6. Replies: 8
    Last Post: 08-31-2013, 03:20 AM
  7. Replies: 4
    Last Post: 01-11-2012, 07:59 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