I have a routine that sends emails when certain criteria are met. This works fine, but I would like it to not send anything if the Days >10. Any thoughts? Thanks for you assistance.
![]()
Please Login or Register to view this content.
I have a routine that sends emails when certain criteria are met. This works fine, but I would like it to not send anything if the Days >10. Any thoughts? Thanks for you assistance.
![]()
Please Login or Register to view this content.
Last edited by Paul; 04-18-2012 at 02:45 PM. Reason: Fixed CODE tags to wrap the code.
Hi JFreeland, without seeing the rest of your procedure, it's hard to say. As it is, perhaps just exiting the procedure might suffice.Replace Sub with Function if you are working in a function.![]()
Please Login or Register to view this content.
If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.
---Keep on Coding in the Free World---
Yes, that works fine. Tried that before, but I think I used End instead of exit. Thanks for your quick response. I appreciate your help.
Mordred, I'm finding that anything with days over 10 stops the routine, which would make sense. Since I have a list of items with various dates, I need it to loop through all of the rows before stopping and choose those that meet the criteria.
This is my sub in it's entirety:
Sub SendEmail()
'Uses late binding
Dim OutlookApp As Object
Dim MItem As Object
Dim cell As Range
Dim Subj As String
Dim EmailAddr As String
Dim Recipient As String
Dim Msg As String
Dim Document As String
Dim Days As Variant
'Create Outlook object
Set OutlookApp = CreateObject("Outlook.Application")
'Loop through the rows
For Each cell In Columns("D").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "*@*" Then
'Get the data
Subj = "Compliance Reminder"
Recipient = cell.Offset(0, -3).Value
EmailAddr = cell.Value
Document = cell.Offset(0, -1).Value
Days = cell.Offset(0, 2).Value
'Compose message
If Days > 10 Then
Exit Sub
ElseIf Days < 10 Then
Msg = Recipient & vbCrLf & vbCrLf
Msg = Msg & "This is a live test of the Regulatory Agency Report compliance system. "
Msg = Msg & "This message was automatically generated in Excel. Please disregard "
Msg = Msg & "the message below, it is "
Msg = Msg & "for test purposes only. Please let me know that you received this email." & vbCrLf & vbCrLf & vbCrLf
Msg = Msg & "This is a reminder that the "
Msg = Msg & Document
Msg = Msg & " is due to be filed in "
Msg = Msg & Days
Msg = Msg & " days. Please let me know if you have filed this report"
Msg = Msg & " or when you expect to file it." & vbCrLf & vbCrLf
Msg = Msg & "Regards," & vbCrLf & vbCrLf
Msg = Msg & "John Freeland" & vbCrLf
Msg = Msg & "Staff Accountant" & vbCrLf
Msg = Msg & "Rocky Brands Inc LLC" & vbCrLf
Msg = Msg & "Phone:740-753-9100 x2804" & vbCrLf
Msg = Msg & "john.freeland@rockybrands.com"
ElseIf Days < 0 Then
Msg = Recipient & vbCrLf & vbCrLf
Msg = Msg & "This is a reminder that the "
Msg = Msg & Document
Msg = Msg & " is now overdue and requires immediate attention."
End If
'Create Mail Item and send it
Set MItem = OutlookApp.CreateItem(0) 'olMailItem
With MItem
.To = EmailAddr
.Subject = Subj
.Body = Msg
'.Send
.Save 'to Drafts folder
End With
End If
Next
Set OutlookApp = Nothing
End Sub
Got it fixed!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks