Martyn0299
New Member
- Joined
- Jan 24, 2019
- Messages
- 3
Hello Guys
I have a piece of code that will look at a cell (M) and if the value of the cell is = (yes) then it will take the e-mails stored in cell (I) and the name of the client stored in cell (G) and the it will send the e-mail when i run the code.
Ok so where im heading is if someone could help me modify the code in a way that it will not sent the mail multiple emails to the email that it has already been send maybe have another cell to look at width he value (Mail Send). Also i would like for the e-mails to be send automaticly and not when u run the code but when value in cell (M) changes it will send the mail. I have over 100 clients in database and i need to send mails to them when the data is changed,
Here is the code i have:
Sub Sendmail()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("I").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "M").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Aakash Sehgal"
.Body = "Dear " & Cells(cell.Row, "G").Value _
& vbNewLine & vbNewLine & _
"Please contact us to discuss bringing " & _
"your account up to date"
'You can add files also by use:
'.Attachments.Add ("C:\test.txt")
.Send 'Or use Display
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
I have a piece of code that will look at a cell (M) and if the value of the cell is = (yes) then it will take the e-mails stored in cell (I) and the name of the client stored in cell (G) and the it will send the e-mail when i run the code.
Ok so where im heading is if someone could help me modify the code in a way that it will not sent the mail multiple emails to the email that it has already been send maybe have another cell to look at width he value (Mail Send). Also i would like for the e-mails to be send automaticly and not when u run the code but when value in cell (M) changes it will send the mail. I have over 100 clients in database and i need to send mails to them when the data is changed,
Here is the code i have:
Sub Sendmail()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Columns("I").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "M").Value) = "yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Aakash Sehgal"
.Body = "Dear " & Cells(cell.Row, "G").Value _
& vbNewLine & vbNewLine & _
"Please contact us to discuss bringing " & _
"your account up to date"
'You can add files also by use:
'.Attachments.Add ("C:\test.txt")
.Send 'Or use Display
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub