Automatically send Mail for Due Dates from Excel

Topazpower

Board Regular
Joined
Mar 2, 2009
Messages
63
I have a workbook which consists of the due dates for which my employee has to be paid up.

Is it possible to generate a code which automatically sends an email from excel every day along with the employee name,employee ID and due date along with

the amount to be paid, which should go through the following:


Employee Id is in C2, C3, C4 and so on.... ( It is added periodically )

Employee Name is in D2, D3, D4 and so on....( It is added periodically )

Employee Salary is in J2, J3, J4, and so on....( It is added periodically )


Due Dates for 1st employee is feeded in k2,l2,m2,n2,o2,p2,q2 etc.....
2nd employee is feeded in k3,l3,m3,n3,o3,p3,q3 etc.....
3rd employee is feeded in k4,l4,m4,n4,o4,p4,q4 etc.....

and so on...


The report should be in two forms i.e., 7 days before due date


and

one month before due date.



Kindly help


Jane.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Can you supply some dates and also due dates. and formatting of dates

and supply more detail in regards to what information is in the sheet examples

How you update the sheet, might be best if you post the sheet if you can, before and after update and what you want to see in the email.

Excel tables to the web >> http://www.excel-jeanie-html.de/index.php?f=1
 
Upvote 0
I would like to have the Employees name and Id numbers list along with the salary details payable which is due to them.

I need this list 7 days before the due date falls and the same list before a month of the due date falls.


Probably, Every week or every 3 days, new employees will be added. So, all Employees and their respective ids, salary and their due dates for salary will be added in a row one under the other.

I have attached the workbook herewith. Pls help.

Regards
Jane.




Excel Workbook
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAG
1S.NoRef NoEmployee IDEmployee NameDaysOTBasicDOJAmount Payable1st Due2nd Due3rd Due4th5th6th7th8th9th10th11th12th13th14th15th16th17th18th19th20th21st22nd23rd24th
21109MDB100001John30050012-Mar-0950011-Apr-0911-May-0910-Jun-0910-Jul-0909-Aug-0908-Sep-0908-Oct-0907-Nov-0907-Dec-0906-Jan-1005-Feb-1007-Mar-1006-Apr-1006-May-1005-Jun-1005-Jul-1004-Aug-1003-Sep-1003-Oct-1002-Nov-1002-Dec-1001-Jan-1131-Jan-1102-Mar-11
32110MDB100002Rivera30050014-Mar-0950013-Apr-0913-May-0912-Jun-0912-Jul-0911-Aug-0910-Sep-0910-Oct-0909-Nov-0909-Dec-0908-Jan-1007-Feb-1009-Mar-1008-Apr-1008-May-1007-Jun-1007-Jul-1006-Aug-1005-Sep-1005-Oct-1004-Nov-1004-Dec-1003-Jan-1102-Feb-1104-Mar-11
43111MDB100003Mary30050014-Mar-0950013-Apr-0913-May-0912-Jun-0912-Jul-0911-Aug-0910-Sep-0910-Oct-0909-Nov-0909-Dec-0908-Jan-1007-Feb-1009-Mar-1008-Apr-1008-May-1007-Jun-1007-Jul-1006-Aug-1005-Sep-1005-Oct-1004-Nov-1004-Dec-1003-Jan-1102-Feb-1104-Mar-11
54112MDB100004Sweta30050014-Mar-0950013-Apr-0913-May-0912-Jun-0912-Jul-0911-Aug-0910-Sep-0910-Oct-0909-Nov-0909-Dec-0908-Jan-1007-Feb-1009-Mar-1008-Apr-1008-May-1007-Jun-1007-Jul-1006-Aug-1005-Sep-1005-Oct-1004-Nov-1004-Dec-1003-Jan-1102-Feb-1104-Mar-11
65113MDB100005Brian30050017-Mar-0950016-Apr-0916-May-0915-Jun-0915-Jul-0914-Aug-0913-Sep-0913-Oct-0912-Nov-0912-Dec-0911-Jan-1010-Feb-1012-Mar-1011-Apr-1011-May-1010-Jun-1010-Jul-1009-Aug-1008-Sep-1008-Oct-1007-Nov-1007-Dec-1006-Jan-1105-Feb-1107-Mar-11
76114MDB100006Fina30050017-Mar-0950016-Apr-0916-May-0915-Jun-0915-Jul-0914-Aug-0913-Sep-0913-Oct-0912-Nov-0912-Dec-0911-Jan-1010-Feb-1012-Mar-1011-Apr-1011-May-1010-Jun-1010-Jul-1009-Aug-1008-Sep-1008-Oct-1007-Nov-1007-Dec-1006-Jan-1105-Feb-1107-Mar-11
87
98
109
Sheet1
 
Upvote 0
Ok this is what I have so far it is still in progress and one of the other guys could pick this up and tidy it up as I think there is a bit of clutter in it.

Code:
Sub test()
Dim r, c, r2, c2, r3 As Integer
r = 2
c = 10
r2 = 1
c2 = 1
r3 = 1
orig = ActiveSheet.Name
Sheets.Add.Name = ("Email")
Sheets(orig).Activate
'Week Due
Do Until Cells(r3, 1) = ""
If Cells(r, c) - Date < "0" Then
c = c + 1
ElseIf Cells(r, c) - Date < "7" Then
Rows(r).Copy
Sheets("Email").Activate
Rows(r2).PasteSpecial
Sheets(orig).Activate
r2 = r2 + 1
c2 = c2 + 1
c = c + 1
r = r + 1
End If
r3 = r3 + 1
Loop

End Sub

Please note that this is the first part... i.e getting out the people due for this week, just working on the email part then move onto the month sue part and email.
 
Upvote 0
Ok here is what I have got... not sure if you wanted headers for the sheets emailed or if you wanted this info into the actual email but you can customise it so that weekly goes to one and monthly goes to another with an if statement if needed...

Please note that you will have to update the email address INSERT EMAIL ADDRESS HERE.

Code:
Sub test()
    Dim FileExtStr As String
    Dim FileFormatNum As Long
    Dim Sourcewb As Workbook
    Dim Destwb As Workbook
    Dim TempFilePath As String
    Dim TempFileName As String
    Dim r, c, r2, c2, r3 As Integer
r = 2
c = 10
r2 = 1
c2 = 1
r3 = 1
orig = ActiveSheet.Name
Sheets.Add.Name = ("Email Weekly")
Sheets(orig).Activate
'Week Due
Do Until Cells(r3, 1) = ""
If Cells(r, c) - Date < "0" Then
c = c + 1
ElseIf Cells(r, c) - Date < "7" Then
Range("C" & r & " , D" & r & ", G" & r).Copy
Sheets("Email Weekly").Activate
Rows(r2).PasteSpecial
Sheets(orig).Activate
Rows(r).Delete
r2 = r2 + 1
c2 = c2 + 1
c = c + 1
r = r + 1
End If
r3 = r3 + 1
Loop
Sheets("Email Weekly").Activate
Application.Run "email"
Application.DisplayAlerts = False
Sheets("Email Weekly").Delete
Application.DisplayAlerts = True


Sheets.Add.Name = ("Email Monthly")
Sheets(orig).Activate
'Monthly Due
r = 2
c = 10
r2 = 1
c2 = 1
r3 = 1
Do Until Cells(r3, 1) = ""
If Cells(r, c) - Date > "7" Then
c = c + 1
ElseIf Cells(r, c) - Date < "30" Then

Range("C" & r & " , D" & r & ", G" & r).Copy
Sheets("Email Monthly").Activate
Rows(r2).PasteSpecial
Sheets(orig).Activate
r2 = r2 + 1
c2 = c2 + 1
c = c + 1
r = r + 1
End If
r3 = r3 + 1
Loop
Sheets("Email Monthly").Activate
Application.Run "email"
Application.DisplayAlerts = False
application.quit
Application.DisplayAlerts = True
End Sub
Sub email()
    'Emailing section
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With

    Set Sourcewb = ActiveWorkbook
    If ActiveSheet.Name = "Email Weekly" Then
    Subject = "Weekly Due"
    ElseIf ActiveSheet.Name = "Email Monthly" Then
    Subject = "Monthly Due"
    End If
    'Copy the sheet to a new workbook
    ActiveSheet.Copy
    Set Destwb = ActiveWorkbook

    'Determine the Excel version and file extension/format
    With Destwb
        If Val(Application.Version) < 12 Then
            'You use Excel 97-2003
            FileExtStr = ".xls": FileFormatNum = -4143
        Else
            'You use Excel 2007, we exit the sub when your answer is
            'NO in the security dialog that you only see  when you copy
            'an sheet from a xlsm file with macro's disabled.
            If Sourcewb.Name = .Name Then
                With Application
                    .ScreenUpdating = True
                    .EnableEvents = True
                End With
                MsgBox "Your answer is NO in the security dialog"
                Exit Sub
            Else
                Select Case Sourcewb.FileFormat
                Case 51: FileExtStr = ".xlsx": FileFormatNum = 51
                Case 52:
                    If .HasVBProject Then
                        FileExtStr = ".xlsm": FileFormatNum = 52
                    Else
                        FileExtStr = ".xlsx": FileFormatNum = 51
                    End If
                Case 56: FileExtStr = ".xls": FileFormatNum = 56
                Case Else: FileExtStr = ".xlsb": FileFormatNum = 50
                End Select
            End If
        End If
    End With

    '    'Change all cells in the worksheet to values if you want
    '    With Destwb.Sheets(1).UsedRange
    '        .Cells.Copy
    '        .Cells.PasteSpecial xlPasteValues
    '        .Cells(1).Select
    '    End With
    '    Application.CutCopyMode = False

    'Save the new workbook/Mail it/Delete it
    TempFilePath = Environ$("temp") & "\"
    TempFileName = Subject & " " & Sourcewb.Name & " " _
                 & Format(Now, "dd-mmm-yy h-mm-ss")

    With Destwb
        .SaveAs TempFilePath & TempFileName & FileExtStr, _
                FileFormat:=FileFormatNum
        On Error Resume Next
        .SendMail "INSERT EMAIL ADDRESS HERE", _
                  Subject
        On Error GoTo 0
        .Close SaveChanges:=False
    End With

    'Delete the file you have send
    Kill TempFilePath & TempFileName & FileExtStr

    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top