SAFranklin
New Member
- Joined
- Jan 28, 2015
- Messages
- 6
Hey all, frustrations have long since set in so I'm looking for a little help due to my limitations. The code below is set to automatically provide an e-mail once zTardy reaches a value that exceeds zTardyLimit. This is one of the steps that I need to get accomplished however I am really struggling with the other two steps to this process so it will be fool proof and I am hoping to get a little help.
I also need the code to:
1) Send an email each time the value increases in zTardy. (Not only when the value initially exceeds the zTardyLimit) However, it cannot send another e-mail when the value of zTardy decreases, even if it does not decrease below the current zTardyLimit value.
2) Place the date the e-mail was sent in the same row, adjacent column.
Sub sendTardies()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
zCount = [tardyCount]
If zCount = 0 Then
Exit Sub
End If
zTardyLimit = [tardyLimit]
zLastRow = Cells(Rows.Count, "B").End(xlUp).Row
temp = "AE7:AE" & zLastRow
For Each cell In Range(temp)
zTardy = cell.Value
If zTardy > zTardyLimit Then
zRow = cell.Row
zName = Cells(zRow, "B")
strbody = ""
strbody = strbody & "HR Manager,"
strbody = strbody & vbCr & vbCr
strbody = strbody & zName & " currently has " & zTardy & " tardies in the past year "
strbody = strbody & "and needs to have his/her attendance reviewed."
strbody = strbody & vbCr & vbCr
strbody = strbody & "Thanks"
On Error Resume Next
With OutMail
.to = "xxxxxx@xxxxx.com"
.CC = ""
.BCC = ""
.Subject = zName & " Attendance"
.Body = strbody
.Send
End With
On Error GoTo 0
zSent = zSent + 1
saywhat = "processing " & zSent & " of " & zCount
Application.StatusBar = saywhwat
End If
Next
Application.StatusBar = ""
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
I also need the code to:
1) Send an email each time the value increases in zTardy. (Not only when the value initially exceeds the zTardyLimit) However, it cannot send another e-mail when the value of zTardy decreases, even if it does not decrease below the current zTardyLimit value.
2) Place the date the e-mail was sent in the same row, adjacent column.
Sub sendTardies()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
zCount = [tardyCount]
If zCount = 0 Then
Exit Sub
End If
zTardyLimit = [tardyLimit]
zLastRow = Cells(Rows.Count, "B").End(xlUp).Row
temp = "AE7:AE" & zLastRow
For Each cell In Range(temp)
zTardy = cell.Value
If zTardy > zTardyLimit Then
zRow = cell.Row
zName = Cells(zRow, "B")
strbody = ""
strbody = strbody & "HR Manager,"
strbody = strbody & vbCr & vbCr
strbody = strbody & zName & " currently has " & zTardy & " tardies in the past year "
strbody = strbody & "and needs to have his/her attendance reviewed."
strbody = strbody & vbCr & vbCr
strbody = strbody & "Thanks"
On Error Resume Next
With OutMail
.to = "xxxxxx@xxxxx.com"
.CC = ""
.BCC = ""
.Subject = zName & " Attendance"
.Body = strbody
.Send
End With
On Error GoTo 0
zSent = zSent + 1
saywhat = "processing " & zSent & " of " & zCount
Application.StatusBar = saywhwat
End If
Next
Application.StatusBar = ""
Set OutMail = Nothing
Set OutApp = Nothing
End Sub