Hi,
I am writing an outlook macro to send automated mails to our employees. I want to use multiple lines in the message body. Can someone help me with the code to work this out.
Tks,Abhijit
Sub SendAnEmailWithOutlook()
Dim OLF As Outlook.MAPIFolder, olMailItem As Outlook.MailItem
Dim ToContact As Outlook.Recipient
Set xl = GetObject(, "Excel.Application")
Set w = xl.workbooks.Open("C:\pdf\data.xls")
Set ws = w.sheets("Sheet1")
Dim atch As Integer
Dim i As Integer
Dim e_mail As String
i = 1
For i=1 to 200
e_mail = ws.cells(i, 1).Value
atch = ws.cells(i, 2).Value
Set OLF = GetObject("", "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set olMailItem = OLF.Items.Add
With olMailItem
olMailItem.subject = "Change in Appointment Letter Clause"
Set ToContact = olMailItem.Recipients.Add(e_mail)
olMailItem.body = "Dear Employee,
Please note that we have modified a clause in the appointment letter regarding the confirmation process. Attached here is the letter with revised clause.
Request you to kindly sign and return a copy of the letter for our records.
Regards,
HR Team " & Chr(13)
olMailItem.Attachments.Add "C:\pdf\ & atch & ".pdf", olByValue, , "Attachment"
olMailItem.Send
Set ToContact = Nothing
End With
Next i
Set olMailItem = Nothing
Set OLF = Nothing
End Sub
I am writing an outlook macro to send automated mails to our employees. I want to use multiple lines in the message body. Can someone help me with the code to work this out.
Tks,Abhijit
Sub SendAnEmailWithOutlook()
Dim OLF As Outlook.MAPIFolder, olMailItem As Outlook.MailItem
Dim ToContact As Outlook.Recipient
Set xl = GetObject(, "Excel.Application")
Set w = xl.workbooks.Open("C:\pdf\data.xls")
Set ws = w.sheets("Sheet1")
Dim atch As Integer
Dim i As Integer
Dim e_mail As String
i = 1
For i=1 to 200
e_mail = ws.cells(i, 1).Value
atch = ws.cells(i, 2).Value
Set OLF = GetObject("", "Outlook.Application").GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set olMailItem = OLF.Items.Add
With olMailItem
olMailItem.subject = "Change in Appointment Letter Clause"
Set ToContact = olMailItem.Recipients.Add(e_mail)
olMailItem.body = "Dear Employee,
Please note that we have modified a clause in the appointment letter regarding the confirmation process. Attached here is the letter with revised clause.
Request you to kindly sign and return a copy of the letter for our records.
Regards,
HR Team " & Chr(13)
olMailItem.Attachments.Add "C:\pdf\ & atch & ".pdf", olByValue, , "Attachment"
olMailItem.Send
Set ToContact = Nothing
End With
Next i
Set olMailItem = Nothing
Set OLF = Nothing
End Sub
Last edited: