I want the Excel VBA code to automatically send me reminders about contacting clients when next deadline comes
Other things seem to work but it does not send me the mail as intended and give me a Compile Error
Here is the code:
Sub datesexcelvba() <- (and here)
Dim myApp As Outlook.Application <- (problem is here)
Dim mymail As Outlook.MailItem
Dim mydate1 As Date
Dim mydate2 As Long
Dim datetoday1 As Date
Dim datetoday2 As Long
Dim x As Long
lastrow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To lastrow
mydate1 = Cells(x, 12).Value
mydate2 = mydate1
Cells(x, 15).Value = mydate2
datetoday1 = Date
datetoday2 = datetoday1
Cells(x, 16).Value = datetoday
If mydate2 - datetoday2 = 0 Then
Set myApp = New Outlook.Application
Set mymail = myApp.CreateItem(olMailItem)
mymail.To = Cells(x, 11).Value
With mymail
.Subject = "Reminder"
.Body = Cells(x, 20).Text
.Display
'.send
End With
Cells(x, 13) = "Reminder sent"
Cells(x, 13).Interior.ColorIndex = 46
Cells(x, 13).Font.ColorIndex = 2
Cells(x, 13).Font.Bold = True
Cells(x, 14).Value = mydate2 - datetoday2
End If
Next
Set myApp = Nothing
Set mymail = Nothing
End Sub