I have a worksheet with given data,
I need to email the data using Microsoft Outlook in the required format for a specific date.
Say the date is 05 Jan 2015.
This is how the email should look,
The code is written in the modules of the Excel 2007 workbook,
Public Function FormatEmail(Sourceworksheet As Worksheet, Recipients As Range, CoBDate As Date)
Dim OutApp As Object
Dim OutMail As Object
Dim rows As Range
On Error GoTo FormatEmail_Error
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
For Each rows In Recipients.Cells.SpecialCells(xlCellTypeConstants)
If rows.value Like "?*@?*.?*" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = rows.value
.Subject = "Reminder"
.Body = "Hi All, " & vbNewLine & _
vbNewLine
.display
End With
On Error GoTo 0
Set OutMail = Nothing
End If
Next rows
On Error GoTo 0
Exit Function
FormatEmail_Error:
Set OutApp = Nothing
Application.ScreenUpdating = True
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure FormatEmail of Module modOutlook"
End Function