Hi guys
I'm trying to write a code to send an automatic mail if some conditions are met and on a specific time. However when I call the sub which then is supposed to launch the mail sub, it keeps giving me a message that it can't find my MailObsdates code.
Can you help me with this please?
[VBA]Sub MailObsdates()
'ActiveSheet.Calculate
Dim OutApp As Object
Dim OutMail As Object
Dim i As Integer
Dim z, a As String
Dim Subject As String
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For i = 3 To 500
If Sheet1.Cells(i, 1) = Sheet1.Cells(i, 8) And Sheet1.Cells(i, 12) = "No" Then
w = Sheet1.Cells(i, 11)
z = Sheet1.Cells(i, 10)
a = Sheet1.Cells(i, 13)
b = Sheet1.Cells(i, 14)
c = Sheet1.Cells(i, 15)
d = Sheet1.Cells(i, 16)
strbody = "Dear "
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = w
.CC = a
.BCC = b
.Subject = "hello " & Sheet1.Cells(i, 3) & " "
.Body = strbody
.send
End With
On Error GoTo 0
Set OutMail = Nothing
Sheet1.Cells(i, 12) = "Yes"
Else
End If
Next i
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
Call TimeApp
End Sub
Sub TimeApp()
ActiveSheet.Calculate
Application.OnTime TimeValue("18:16:00"), ("MailObsdates")
End Sub[/VBA]
Thankx a lot