Public Sub SendBasicEmail()
On Error GoTo Proc_Error
'
'
'
Dim oOutlook As Object
Dim oMessage As Object
Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim objOutlookAttach As Object
Const olMailItem As Long = 0
Const olTo As Long = 1
Dim intRow As Integer
Dim intLastRow As Integer
Dim arrWorkArea As Variant
Dim strBody As String
Dim strName As String
strName = Range("B3").Value
'New code
Dim MyRange As Range
Set MyRange = Range("E4,E6,E7,E8,E9,E10,E12,E13,E15,E16,E17,G4,G6,G7,G8,G9,G10,G12,G13,G15,G16,G17,H4,H6,H7,H8,H9,H10,H12,H13,H15,H16,H17")
Dim FoundCell As Variant
On Error Resume Next
Set FoundCell = MyRange.Find(what:="", matchbyte:=True)
On Error GoTo 0
If Not (FoundCell Is Nothing) Then
MsgBox "Cell " & FoundCell.Address(False, False) & " is blank." & _
vbNewLine & "You can't send this until you fill it out.", vbOKOnly
Exit Sub
End If
'Changed this string as well
strBody = "Dear All" & vbNewLine & vbNewLine & _
"Please find the attached One on One templete." & vbNewLine & vbNewLine & _
"Regards," & vbNewLine & _
strName
'
' Compose and send e-mail
'
Set oOutlook = CreateObject("Outlook.Application")
Set oMessage = oOutlook.CreateItem(olMailItem)
With oMessage
oMessage.Attachments.Add ActiveWorkbook.FullName
Set objOutlookRecip = .Recipients.Add("Rajender_Prasad@XYZ.com")
objOutlookRecip.Type = olTo
objOutlookRecip.Resolve
Set objOutlookRecip = .Recipients.Add("Rajender_Prasad@XYZ.com")
objOutlookRecip.Type = olTo
objOutlookRecip.Resolve
Set objOutlookRecip = .Recipients.Add("Rajender_Prasad@XYZ.com")
objOutlookRecip.Type = olTo
objOutlookRecip.Resolve
.CC = "Rajender_Prasad@infosys.com"
.Subject = "One On One " & strName
.Body = strBody
' .Importance = olImportanceHigh
.Display
'or
.Save
.Send
End With
Proc_Exit:
Set oMessage = Nothing
Set oOutlook = Nothing
Exit Sub
Proc_Error:
Select Case Err
Case 287 ' Outlook not open
MsgBox "Please open Outlook to send email", vbOKOnly
Resume
Case Else
MsgBox "Error " & CStr(Err) & ": " & Err.Description
Resume Proc_Exit
End Select
Exit Sub
End Sub