sspatriots
Well-known Member
- Joined
- Nov 22, 2011
- Messages
- 585
- Office Version
- 365
- Platform
- Windows
Good morning,
I found the code below from Ron de Bruin's website that I think I can use, but can't get it to work at all. Also I need it to start in cell A5 and loop down until the first blank cell in that column and stop. Any help would be greatly appreciated. My columns are as follows:
AI = Customer Contact's Name
AL = Contact's E-mail Address
AO = Yes/No, If "Yes" send the E-mail
Right now the code doesn't do anything, so not sure what I'm missing.
I found the code below from Ron de Bruin's website that I think I can use, but can't get it to work at all. Also I need it to start in cell A5 and loop down until the first blank cell in that column and stop. Any help would be greatly appreciated. My columns are as follows:
AI = Customer Contact's Name
AL = Contact's E-mail Address
AO = Yes/No, If "Yes" send the E-mail
Right now the code doesn't do anything, so not sure what I'm missing.
VBA Code:
Sub Test1()
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
'Working in Office 2000-2016
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("AL").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "AO").Value) = "Yes" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "Reminder"
.Body = "Dear " & Cells(cell.Row, "AI").Value _
& vbNewLine & vbNewLine & _
"Please contact us to discuss bringing " & _
"your account up to date by & Cells(cell.Row, "L").Value & ".""
'You can add files also like this
'.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