A
AL
Below I have some code (thanks GS) to send an email automatically with
a custom message. Is it possible to run when the workbook is first
open?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim dteOlderThan As String
Dim szMailTo As String, szCustomMsg As String
Set rng = Intersect(Target, Range("X:X"))
dteOlderThan = Cells(Target.Row, "B")
szMailTo = Cells(Target.Row, "L")
szCustomMsg = Cells(Target.Row, "C")
If Not rng Is Nothing Then
If Target.Value = "No" And _
dteOlderThan <= (Date - 14) Then _
Mail szMailTo, szCustomMsg
End If
End Sub
Sub Mail(szMailTo As String, szCustomMsg As String)
Dim OutApp As Object
Dim OutMail As Object
Dim strcc As String, strbcc As String
Dim strsub As String, strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strcc = ""
strbcc = ""
strsub = "Important message"
strbody = "A SPAD Advice Notice is required for signal:" &
vbNewLine & vbNewLine & _
szCustomMsg
With OutMail
.To = szMailTo
.cc = strcc
.BCC = strbcc
.Subject = strsub
.Body = strbody
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Thanks
AL
a custom message. Is it possible to run when the workbook is first
open?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim dteOlderThan As String
Dim szMailTo As String, szCustomMsg As String
Set rng = Intersect(Target, Range("X:X"))
dteOlderThan = Cells(Target.Row, "B")
szMailTo = Cells(Target.Row, "L")
szCustomMsg = Cells(Target.Row, "C")
If Not rng Is Nothing Then
If Target.Value = "No" And _
dteOlderThan <= (Date - 14) Then _
Mail szMailTo, szCustomMsg
End If
End Sub
Sub Mail(szMailTo As String, szCustomMsg As String)
Dim OutApp As Object
Dim OutMail As Object
Dim strcc As String, strbcc As String
Dim strsub As String, strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strcc = ""
strbcc = ""
strsub = "Important message"
strbody = "A SPAD Advice Notice is required for signal:" &
vbNewLine & vbNewLine & _
szCustomMsg
With OutMail
.To = szMailTo
.cc = strcc
.BCC = strbcc
.Subject = strsub
.Body = strbody
.Send
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Thanks
AL