Hello,
I send mail with this script and the contents of body are cell values, now i want to add the contents from ms word which is in "c:\Email Contents\covering.doc". Please some guide me doing this.
I send mail with this script and the contents of body are cell values, now i want to add the contents from ms word which is in "c:\Email Contents\covering.doc". Please some guide me doing this.
Code:
Option Explicit
Sub Send_Files()
Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim sh As Worksheet
Dim cell As Range
Dim FileCell As Range
Dim rng As Range
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set sh = Sheets("sendemail")
Set OutApp = CreateObject("Outlook.Application")
For Each cell In sh.Columns("G").Cells.SpecialCells(xlCellTypeConstants)
'Enter the path/file names in the C:Z column in each row
Set rng = sh.Cells(cell.Row, 1).Range("K1:Z1")
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "H").Value) = "yes" _
And LCase(Cells(cell.Row, "I").Value) <> "send" And _
Application.WorksheetFunction.CountA(rng) > 0 Then
Set OutMail = OutApp.CreateItem(olMailItem)
On Error Resume Next
With OutMail
.To = cell.Value
'.CC = ""
.Subject = "Reports & Statements "
.Body = "Dear Sir / Madam," & vbNewLine & vbNewLine & _
"Status : " & cell.Offset(0, 3).Value _
& vbNewLine & vbNewLine & _
"Report No.: " & cell.Offset(0, -5).Value _
& vbNewLine & vbNewLine
[U][B]Get Contents from .doc file
[/B][/U]
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
.Display 'Or use Send
End With
On Error GoTo 0
Cells(cell.Row, "I").Value = "send"
Set OutMail = Nothing
End If
Next cell
cleanup:
Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub