I currently have macros built that will execute when a cell value dips below a certain number. My issue, these are live prices, and that number will tick constantly, prompting the macro to run all day. Ideally this macro calls the email macro once a day, given the parameters are met.
This Excel file will sit on a computer that runs 24/7, so no issue in closing and re-opening.
Here is the code for both:
Private Sub Worksheet_Calculate()
If Range("C15").Value < 72 Then
Call Send_Email
End If
End Sub
Sub Send_Email()
Dim pApp As Object
Dim pMail As Object
Dim pBody As String
Dim rng As Range
Set rng = Range("B6:C16")
Set pApp = CreateObject("Outlook.Application")
Set pMail = pApp.CreateItem(0)
On Error Resume Next
With pMail
.To = "gmail.com"
.CC = ""
.BCC = ""
.Subject = "Account Action Price Notification"
.Body = "Hello, our recommended action price for BLANK of $72 has been hit." & vbNewLine & vbNewLine & _
"Thank you."
'Below displays the email and allows it to paste
.Display
Dim wdDoc As Object '## Word.Document
Dim wdRange As Object '## Word.Range
Set wdDoc = pMail.GetInspector.WordEditor
Set wdRange = wdDoc.Range(0, 0)
wdRange.InsertAfter vbCrLf & vbCrLf
'Copy the range in-place
rng.Copy
wdRange.Paste
'Below will auto send the email when apostrophe is removed
'.Send
End With
On Error GoTo 0
Set pMail = Nothing
Set pApp = Nothing
End Sub
I have tried working solutions from here: VBA Run Macro Once a Day
However, I am unable to get this to properly run.