Outlook Email Automation Examples
Outlook Email Automation Examples
1) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub SendMail_Bangalore()
Dim oApp As Outlook.Application
Dim OEmail As Outlook.MailItem
Dim signature As String
Dim str As String
Dim loc As String
Set oApp = New Outlook.Application
Set OEmail = oApp.CreateItem(olMailItem)
Dim olNS As Outlook.Namespace
Set olNS = Outlook.Application.GetNamespace("MAPI")
OEmail.SendUsingAccount = olNS.Accounts.Item(1)
loc = "Bangalore"
If Sheet1.Range("b10").Value < 2 Then
str = "Hi All," & "<br/><br/>" & "Mentioned Package ID " & Sheet1.Range("b9").Value & " has been renewed for next " & Sheet1.Range("b10").Value _
& " day. Service will start from " & Format(Sheet1.Range("b11").Value, "DD-MMM") & "." & "<br/><br/>"
Else
str = "Hi All," & "<br/><br/>" & "Mentioned Package ID " & Sheet1.Range("b9").Value & " has been renewed for next " & Sheet1.Range("b10").Value _
& " days. Service will start from " & Format(Sheet1.Range("b11").Value, "DD-MMM") & "." & "<br/><br/>"
End If
'With OEmail
' .Display
'End With
With OEmail
'.BodyFormat = olFormatHTML
.Display
.To = Sheet2.Range("b22")
.CC = Sheet2.Range("b23")
.Subject = Sheet1.Range("b7").Value & "/" & Sheet1.Range("b8").Value & "/" & "Renewal required" _
& "/" & loc & "/" & Format(Date, "DD-MMM-YY")
'.HTMLBody = str & rngHTML(Range("A1:B5")) & "<br>" & .HTMLBody
.HTMLBody = str & rngHTML(Sheet1.Range("a13:g17")) & _
.HTMLBody
'.Body = "Hi All" & vbNewLine & vbNewLine & "Have a Nice Day!" & .Body
'.HTMLBody = rngHtml(Range("a1:b10")) & .HTMLBody
End With
'signature = OEmail.Body
End Sub
Comments
Post a Comment