Problem solved! God. I came in this morning, made a single change, and it all works! Here is the code for those that need to send an email triggered by a value in an excel spreadsheet. It will send to multiple recipients (an individual email for each) listed on a contacts sheet using VLookup. This code uses Mac Mail as the mail application.
Sub Send_Email_to_Multiple_Recipients()
'For Excel 2011 for the Mac and Apple Mail
Dim rng As Range
Dim Ash As Worksheet
Dim Rcount As Long
Dim Rnum As Long
Dim FilterRange As Range
Dim FieldNum As Integer
Dim mailAddress As String
On Error GoTo cleanup
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
'Set Contacts sheet as the sheet to filter
Worksheets("Contacts").Activate
Set Ash = ActiveSheet
'Set filter range and filter column (column with names)
Set FilterRange = Ash.Range("A3:B" & Ash.Rows.Count)
FieldNum = 1 'Filter column = A, first column in the FilterRange
'Count of the unique values + the header cell
Rcount = Application.WorksheetFunction.CountA(Ash.Columns(1))
'If there are unique values start the loop
If Rcount >= 2 Then
For Rnum = 2 To Rcount
'Look for the mail address in the Contacts worksheet
mailAddress = ""
On Error Resume Next
mailAddress = Application.WorksheetFunction. _
VLookup(Ash.Cells(Rnum, 1).Value, _
Worksheets("Contacts").Range("A4:D" & _
Worksheets("Contacts").Rows.Count), 2, False)
On Error GoTo 0
If mailAddress <> "" Then
'Filter the FilterRange on the FieldNum column
FilterRange.AutoFilter Field:=FieldNum, _
Criteria1:=Ash.Cells(Rnum, 1).Value
MailFromMacWithMail _
bodycontent:="The project Director says to 'Busta Move' on Implementation. Projected Launch Date is " & Worksheets("Progress").Range("D6") & ".", _
mailsubject:=Worksheets("Progress").Range("C1") & " Validation Breaking News!", _
toaddress:=mailAddress, _
ccaddress:="", bccaddress:="", _
attachment:="", _
displaymail:=False
End If
'Close AutoFilter
Ash.AutoFilterMode = False
Next Rnum
End If
Worksheets("Progress").Range("O37").Value = "Y"
cleanup:
Application.DisplayAlerts = True
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
I hope this is useful to others. Thanks again to Ron de Bruin's excellent VBA coding skills that provided the foundation for this.
Bookmarks