This is continuation of my Previous Article you learnt How to Send Email From Excel VBA, using Gmail and Yahoo Email Account.
In my Previous Article, How to send email from Excel Macro, as you saw how to send email by Excel VBA from Gmail or Yahoo In this article you are going to learn how to send an email automatically by Excel VBA from my Outlook. Here in this you need to make sure that you have Outlook installed in your system where your excel macro is running. Also for sending email your Outlook must be configured already.
Before we get in to the code details, we need to add Microsoft Outlook 12.0 Object Librar reference in your Excel.
If you have not added this Reference then you need to create Outlook Objects run-time.
Sub SendEmailUsingOutlook()
Dim OlApp As New Outlook.Application
Dim myNameSp As Outlook.Namespace
Dim myInbox As Outlook.MAPIFolder
Dim myExplorer As Outlook.Explorer
Dim NewMail As Outlook.MailItem
Dim OutOpen As Boolean
' Check to see if there's an explorer window open
' If not then open up a new one
OutOpen = True
Set myExplorer = OlApp.ActiveExplorer
If TypeName(myExplorer) = "Nothing" Then
OutOpen = False
Set myNameSp = OlApp.GetNamespace("MAPI")
Set myInbox = myNameSp.GetDefaultFolder(olFolderInbox)
Set myExplorer = myInbox.GetExplorer
End If
' If you don't to display your outlook while sending email then comment the below statement
'otherwise you can un-comment
'myExplorer.Display
' Create a new mail message item.
Set NewMail = OlApp.CreateItem(olMailItem)
With NewMail
'.Display ' You don't have to show the e-mail to send it
.Display
.Subject = "Happy New Year"
.To = "abc@email.com"
.Body = "Wishing you happy New Year"
.Attachments.Add ("C:\log.txt")
End With
NewMail.Send
If Not OutOpen Then OlApp.Quit
'Release memory.
Set OlApp = Nothing
Set myNameSp = Nothing
Set myInbox = Nothing
Set myExplorer = Nothing
Set NewMail = Nothing
End Sub
To know How to Send Email from Excel Macro using Gmail and Yahoo Account Read this Article |
hi happy new year to yous all
a beilin
Thanks Alfred and same to you.
Hi,
This format is very good.
Thanks Yogisha !!
Hi Vishwa… i tried tis macro…but my mail s getting stored in outbox… and the mail is not sent. why is it so?
Hi Priya,
Remove this statement .Display from the code and try.
With NewMail
'.Display ' You don't have to show the e-mail to send it
.Display
.Subject = "Happy New Year"
.To = "abc@email.com"
.Body = "Wishing you happy New Year"
.Attachments.Add ("C:log.txt")
End With
Hi ,
Can i have any video reference ..how does this works ..i tried but it dint work
My requirement is i have excel where it get automatic updates from SQL Data Base …now we have to send this excel every day to Group Mails..sometimes we miss to send … with out our manual work …how to automate to send this excel sheet
Kalyan
Hi
I have ahopefully quick question.
How do you use an email adress, from a cell? or example if I have an email in excell i cell A1, how can that be inserted?
Jakob
how can i forces the Language to be Hebrew or make the body Alignment = right
thanx
ori
Hi Vishwamitra,
Your code gives me the type mismatch error. can you help with this?
I am getting this error in
” Set NewMail = OlApp.CreateItem(olMailItem)”
Please help.
THanks again for writing such a nice blog.
hi
is there any macro to copy the any selected range data from excell and email
This web site does not render correctly on my droid – you may want to try and repair that
Hi Vishwamitra,
I want to know small coding to send simple email, can you help me on this,
Email should be like,
Hi ZZZZZZZZ,
Could you please provide us the payment balances of XXXXXXX to be updated in Non-Netting Website for the month of Dec’14.
Please provide us the details ASAP as we need to work with other restricted entities as well and update the same within XXXXXXXX.
Thanks,
Sathish E
Please tell me how to add voting buttons while sending Email from excel VBA.
Hi,
I have a excel macro which sends mail using Outlook. I have configured 2 email accounts (say emailid 1 & email id 2) in outlook for two specific purposes. Whenever I run the macro, all the mails are sent through default email id (say email id 1). Is it possible to send mails using emailid 2.