I am trying to do a vba script so that i run excel using microsoft scheduler and if it finds something which is due in 30 days it will auto0matically send a mail. now for the first column its working fine but for the second it stops. can anyone help me please
Sub Workbook_Open()
Dim lngLast As Long
Dim lngCounter As Long
Application.ScreenUpdating = False
lngLast = Cells(Rows.Count, "AB").End(xlUp).Row
For lngCounter = 2 To lngLast
With Cells(lngCounter, "AB")
If DateDiff("d", Date, .Value) <= 30 Then
*** = "A" & .Row
ass2 = "B" & .Row
ass3 = "AB" & .Row
firstdate = Range(ass3).Value
msg = DateDiff("d", Date, firstdate)
Set objEmail = CreateObject("CDO.Message")
With objEmail
With .Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
= "smtp.go.net.mt"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") _
= "30"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") _
= "2"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
= "25"
.Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") _
= "instrumentation@aurobindomalta.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") _
= "0"
.Update
End With
.To = "medio@onvol.net"
.From = "instrumentation@aurobindomalta.com"
.Subject = "Calibration due for" & Space(2) & Range(***).Value
.TextBody = Range(ass2).Value & "(" & Range(***).Value & ")" & Space(2) & "has its calibration due in" & Space(2) & msg & Space(2) & "days. Kindly contact personell in charge."
.send
End With
Set objEmail = Nothing
End If
End With
Next lngCounter
Application.ScreenUpdating = True
cal
End Sub
Sub cal()
Dim lngLast As Long
Dim lngCounter As Long
Application.ScreenUpdating = False
lngLast = Cells(Rows.Count, "AC").End(xlUp).Row
For lngCounter = 2 To lngLast
With Cells(lngCounter, "AC")
If DateDiff("d", Date, .Value) <= 30 Then
*** = "A" & .Row
ass2 = "B" & .Row
ass3 = "AC" & .Row
firstdate = Range(ass3).Value
msg = DateDiff("d", Date, firstdate)
Set objEmail = CreateObject("CDO.Message")
With objEmail
With .Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
= "smtp.go.net.mt"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") _
= "30"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") _
= "2"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
= "25"
.Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") _
= "instrumentation@aurobindomalta.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") _
= "0"
.Update
End With
.To = "medio@onvol.net"
.From = "instrumentation@aurobindomalta.com"
.Subject = "Calibration due for" & Space(2) & Range(***).Value
.TextBody = Range(ass2).Value & "(" & Range(***).Value & ")" & Space(2) & "has its calibration due in" & Space(2) & msg & Space(2) & "days. Kindly contact personell in charge."
.send
End With
Set objEmail = Nothing
End If
End With
Next lngCounter
Application.ScreenUpdating = True
pm
End Sub
Sub pm()
Dim lngLast As Long
Dim lngCounter As Long
Application.ScreenUpdating = False
lngLast = Cells(Rows.Count, "AD").End(xlUp).Row
For lngCounter = 2 To lngLast
With Cells(lngCounter, "AD")
If DateDiff("d", Date, .Value) <= 30 Then
*** = "A" & .Row
ass2 = "B" & .Row
ass3 = "AD" & .Row
firstdate = Range(ass3).Value
msg = DateDiff("d", Date, firstdate)
Set objEmail = CreateObject("CDO.Message")
With objEmail
With .Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
= "smtp.go.net.mt"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") _
= "30"
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") _
= "2"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
= "25"
.Item("http://schemas.microsoft.com/cdo/configuration/sendemailaddress") _
= "instrumentation@aurobindomalta.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") _
= "0"
.Update
End With
.To = "medio@onvol.net"
.From = "instrumentation@aurobindomalta.com"
.Subject = "Performance monitoring due for" & Space(2) & Range(***).Value
.TextBody = Range(ass2).Value & "(" & Range(***).Value & ")" & Space(2) & "has its performance monitoring due in" & Space(2) & msg & Space(2) & "days. Kindly contact personell in charge."
.send
End With
Set objEmail = Nothing
End If
End With
Next lngCounter
Application.ScreenUpdating = True
End Sub
Instrumentation Logsheet - Copy.zip
Bookmarks