Send email when cells in specific column are changed.

js1127

New Member
Joined
May 3, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I have been trying to get a macro working to send an email when a date is added to a certain column in Excel. I thought I had found the right code. But it is not sending the email when I test it. How do I set this up? I would like an email to go out to the address in a cell when another cell is updated. This is the code I am trying to use. But I am not getting the email.

Sub SendMail()
Dim OutApp As Object
Dim OutMail As Object
Dim RelDate As Range
Dim lastRow As Long
Dim dateCell, dateCell1 As Date

Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
lastRow = Range("A" & Rows.Count).End(xlUp).Row
On Error GoTo cleanup
For Each RelDate In Range("M2:M" & lastRow)
If RelDate = "" Then GoTo 1
dateCell = RelDate.Value
dateCell1 = Cells(RelDate.Row, "L").Value
If dateCell <> dateCell1 Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = Cells(RelDate.Row, "K").Value
.Subject = "Release Date Changed"
.Body = "Dear " & Cells(RelDate.Row, "A").Value _
& vbNewLine & vbNewLine & _
"The release date of " & Cells(RelDate.Row, "H").Value & _
" is changed to " & dateCell _
& vbNewLine & vbNewLine _
& vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
"Your Name"
.send
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Cells(RelDate.Row, "L").Value = dateCell
RelDate.ClearContents
1: Next RelDate
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
 
That is waaay better! Have to leave soon for the afternoon but will come back to this. I started coding it but had to stop as questions did arise (the ones I last posted).
One bit of info that might help you is if there is something you don't understand from a responder, use some of the words and Google it and see what you get. I always appreciate someone who does that instead of posting back "what does [this or that] mean?". I mean, buddy, c'mon, put some effort into it!
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
PM sent with sample of email output. PM me if you didn't get it.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,820
Members
449,049
Latest member
cybersurfer5000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top