Hi guys,
I am having a small problem with one of Ron de Bruin's macros. I hope one of you can help me with it.
In the workbook attached, I have the names in column A, e-mails addresses in column B, an auxiliary file in column C and the file to be attached in column D.
I would like to have two different macros: one that would send the e-mails in rows 2-7 and the other to send the e-mails in rows 10-18, always attaching only the file in column D.
How can I modify the following code to make it work?
Thanks in advance!!!
Sub Prepara_Emails()
Dim OutApp As Object
Dim OutMail As Object
Dim sh As Worksheet
Dim cell As Range, FileCell As Range, rng As Range
With Application
.DisplayAlerts = False
.EnableEvents = False
.ScreenUpdating = False
End With
NOME = "E-mail Subject"
Set sh = Sheets("Macros")
Set OutApp = CreateObject("Outlook.Application")
For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants)
Set rng = sh.Cells(cell.Row, 1).Range("D1:D1")
If cell.Value Like "?*@?*.?*" And _
Application.WorksheetFunction.CountA(rng) > 0 Then
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = cell.Value
.cc = "Me"
.Subject = NOME
.HTMLBody = "<html><body> Hi</body></html>"
For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
If Trim(FileCell) <> "" Then
If Dir(FileCell.Value) <> "" Then
.Attachments.Add FileCell.Value
End If
End If
Next FileCell
.Display
End With
Set OutMail = Nothing
End If
Next cell
Set OutApp = Nothing
With Application
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
Example2.xlsx
Bookmarks