Saturday, March 18, 2017

Sent mail through Outlook

Macro to send mail through Outlook


Sub Outlook_Basic()

'Variable to create Outlook. Used reference MS Outlook library.
Dim OApp As Outlook.Application
Dim OEmail As Outlook.MailItem

'Intialization of outlook
Set OApp = New Outlook.Application
'Setting new mail
Set OEmail = Outlook.CreateItem(olMailItem)

'Action with the mail
With OEmail
    .Display
    .To = "kvinay.g@gmail.com"
    .CC = "kvinay.g@gmail.com"
    .Body = "Hi All, This is a test Outlook mail. "
    .Subject = "Test Mail"
    .Attachments.Add (Environ("UserProfile") & "\desktop\test.xlsm")
    .Send
End With

MsgBox "Done!"
End Sub

No comments:

Post a Comment

*INTERVIEW QUESTIONS

* Ques 01. What is the difference between ByVal and ByRef and which is default ? Ans-  ByRef : If you pass an argument by reference when...