Hello, I use the following code to send email when the cell value reaches my criteria:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If (Range("L10").Value > Range("M4").Value AND Range("M10").Value = "YES") OR (Range("L12").Value > Range("M4") AND Range("M12").Value = "YES") Then
Call Mail_Workbook
End If
End Sub
Sub Mail_Workbook()
Application.ScreenUpdating = False
Dim OutApp As Object
Dim OutMail As Object
'Create Initial variables
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'Email
On Error Resume Next
With OutMail
.to = "mail@mail.com"
.CC = ""
.BCC = ""
.Subject = "Alert"
.Body = "Good value"
'.Attachments.Add (FilePath) 'Optional if you have an attachment
.Display
.Send 'Optional to automate sending of email.
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
However it needs to check the cell value every 5 minutes or so as the data in the cell is changing as it is pulled from the internet. How to change the code above to add the 5 minute check periodicity?
Any help is appreciated, thanks.
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If (Range("L10").Value > Range("M4").Value AND Range("M10").Value = "YES") OR (Range("L12").Value > Range("M4") AND Range("M12").Value = "YES") Then
Call Mail_Workbook
End If
End Sub
Sub Mail_Workbook()
Application.ScreenUpdating = False
Dim OutApp As Object
Dim OutMail As Object
'Create Initial variables
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.to = "mail@mail.com"
.CC = ""
.BCC = ""
.Subject = "Alert"
.Body = "Good value"
'.Attachments.Add (FilePath) 'Optional if you have an attachment
.Display
.Send 'Optional to automate sending of email.
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
However it needs to check the cell value every 5 minutes or so as the data in the cell is changing as it is pulled from the internet. How to change the code above to add the 5 minute check periodicity?
Any help is appreciated, thanks.