Send separate e-mail to every e-mail address in a column

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
581
Office Version
  1. 365
Platform
  1. 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.

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
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
The following will work :

VBA Code:
Option Explicit


Sub SndEMail()
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, and Outlook 2010.
    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 = Cells(cell.Row, "AL").Value                                'cell.Value
                .Subject = "Reminder"
                .Body = "Dear " & Cells(cell.Row, "AI").Value _
                      & vbNewLine & vbNewLine & _
                        "Please contact us to discuss bringing " & _
                        "your account up to date"
                'You can also add files like this:
                '.Attachments.Add ("C:\test.txt")
                '.Send  'Or use Display.
                .Display
            End With
            On Error GoTo 0
            Set OutMail = Nothing
        End If
    Next cell

cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
That seems to be working. Thank you. I just have one more question. The column "AI" that has the contact names in it has first and last names. Is there a way to extract just the first name from that cell to put in the email body? For example if the contact name were "John Smith", I would need the following:

Dear John,

Please contact us to discuss bringing your account up to date.
 
Upvote 0
VBA Code:
Option Explicit

Sub SndEMail()
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, and Outlook 2010.
    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)
            
            Dim FullName As String
            Dim FirstName As String
            Dim LastName As String
            Dim SpacePos As Integer
            
            FullName = Cells(cell.Row, "AI").Value
            SpacePos = InStr(FullName, " ")
            FirstName = Left(FullName, SpacePos - 1)
            LastName = Right(FullName, Len(FullName) - Len(FirstName))
            
            
            On Error Resume Next
            With OutMail
                .To = Cells(cell.Row, "AL").Value    'cell.Value
                .Subject = "Reminder"
                .Body = "Dear " & FirstName & "," _
                      & vbNewLine & vbNewLine & _
                        "Please contact us to discuss bringing " & _
                        "your account up to date"
                'You can also add files like this:
                '.Attachments.Add ("C:\test.txt")
                '.Send  'Or use Display.
                .Display
            End With
            On Error GoTo 0
            Set OutMail = Nothing
        End If
    Next cell

cleanup:
    Set OutApp = Nothing
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
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.

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
Were you looking at the code for Windows? Ron has a separate site for Mac. Check out this page.
 
Upvote 0
I'm sorry I didn't notice the post marked as Solution. I'm glad this was resolved. The thread came to the top of my list and I should have seen the solution was there already.
 
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,644
Members
449,461
Latest member
kokoanutt

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