Hi,
I am looking for a script that should send an automated email to the email ID in the row with subject line as Description (Column B). It need to check for the end date (Column D)and if it is less than 2 days to the current date it should send an email.
Body of the email need to be as below
Dear Owner (Column F),
Reminder!! You have 2 more days to complete this task.
Regards,
Pradeep Kodali
Please help me in getting a Macro or Script for this.
I have attached the Spread Sheet for your reference.
Thanks in advance for your help!!
Regards,
Pradeep Kodali
Hello Pradeep,
This macro will send the emails out when today's date is 2 days before the end date. A button has been added to the sheet to run the macro. The attached workbook has the macro added.
' Thread: http://www.excelforum.com/excel-programming/790637-script-or-macro-to-send-an-email.html ' Poster: pradeepkodali ' Written: September 01, 2011 ' Author: Leith Ross ' Summary: Send Email from a Worksheet Range using Outlook Public olApp As Object Sub SendEmails() Dim Cell As Range Dim olMail As Object Dim Rng As Range Dim Wks As Worksheet Set Wks = ActiveSheet Set Rng = Wks.Range("A1").CurrentRegion Set Rng = Rng.Offset(1, 0).Resize(RowSize:=Rng.Rows.Count - 1) If olApp Is Nothing Then Set olApp = CreateObject("Outlook.Application") For Each Cell In Rng.Columns(4).Cells 'Column "D" If DateDiff("d", Now(), Cell) = 2 Then Set olMail = olApp.CreateItem(olMailItem) With olMail .To = Cell.Offset(0, 3) 'Column "G" .Subject = Cell.Offset(0, -2) 'Column "B .Body = "Dear Owner " & Cell.Offset(0, 2) & vbCrLf & vbCrLf _ & "Reminder!! You have 2 more days to complete this task." & vbCrLf & vbCrLf _ & "Regards," & vbCrLf & "Pradeep Kodali" .Send End With End If Next Cell 'Logoff and Quit olApp.Quit Set olApp = Nothing End Sub
Last edited by Leith Ross; 09-01-2011 at 07:21 PM. Reason: Corrected date difference problem and typo
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hello Leith,
Thanks for the script. How ever I am unable to send the emails and getting error as "Runtime Error 5: invalid procedure call or argument" and it shows error in below code. Please have a check.
If DateDiff(d, Now(), Cell) = 2 Then
Regards,
Pradeep Kodali
Hello Pradeep,
I guess the change didn't save. Here is what the line should be. the small letter d should be in quotes.
If DateDiff("d", Now(), Cell) = 2 Then
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hi Leith,
Now its throughing RUNTIME error @ .To = Cells.Offset(0, 3) 'Column "G"
Regards,
Pradeep K
Hello Pradeep,
That should be Cell and not Cells. My typing is not very good.
.To = Cell.Offset(0, 3) 'Column "G"
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Thanks Leith!! Its working now as desired.
Will it only work for MS Outlook Client or web emails as well (eg: Gmail)?
Thanks!
Pradeep Kodali
Hello Pradeep,
The macro is written for Outlook. Other email clients, like Gmail, can receive the email once it has been sent.
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Thanks Leith!!
Thanks once again!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks