Thanks TKCZBW!! I have reached almost at result. Below code is working but with some issues. Please look into this.
1) Code is working only for 2nd row.
2) CC is taking all values in that column except single cell value.
3) Some times getting error 91, "object variable or with variable not set" for code "Set OutMail = OutApp.CreateItem(0)"
Sheet's structure -
Names of the people E-mail addresses Filenames CC BCC Subject
Sub Mail_Outlook_With_Signature_Html()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim sh As Worksheet
Dim cell As Range
Dim FileCell As Range
Dim rng As Range
Dim Tomail, CCmail, BCCmail, Subjectmail As String
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set sh = Sheets("Sheet1")
Set OutApp = CreateObject("Outlook.Application")
For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants)
'Enter the path/file names in the C:Z column in each row
Set rng = sh.Cells(cell.Row, 1).Range("C1:Z1")
If cell.Value Like "?*@?*.?*" And _
Application.WorksheetFunction.CountA(rng) > 0 Then
Set OutMail = OutApp.CreateItem(0)
lastrow = ActiveSheet.UsedRange.Rows.Count
For i = 2 To lastrow 'Assume you have headers in row 1
CCmail = CCmail & Cells(i, 4).Value & ";"
BCCmail = BCCMaill & Cells(i, 5).Value & ";"
Next i
Subjectmail = Cells(2, 6).Value 'Assuming only one subject
strbody = "<br>Hello,</br>" & _
"<p>My name is Liz.<br></p>" & _
"<p></p>"
On Error Resume Next
With OutMail
.Display
.To = cell.Value
.CC = CCmail
.BCC = BCCmail
.Subject = Subjectmail
.HTMLBody = strbody & "<br>" & .HTMLBody
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
.Send 'Or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End If
Next cell
Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
Thanks,
Liz
Bookmarks