简体   繁体   中英

Auto Email Send from outlook using excel information from the cell

在此处输入图片说明

I need to send auto email from Excel using Excel Outlook, I was trying coding but unable to do it. I have attached sheet for your reference.

Sub SendEmail()

Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

With OutMail
    .To = "ABC@gmail.com"
    .CC = ""
    .BCC = ""
    .Subject = "Report"
    .Body = "Hello!"
    .Attachments.Add ActiveWorkbook.FullName

    .Send
End With

Set OutMail = Nothing
Set OutApp = Nothing
Application.OnTime TimeValue("17:00:00"), "SendEmail"

End Sub

You will need to reference and login into the Outlook.Namespace before creating the email.

Try adding this to to your code:

Set OutApp = CreateObject("Outlook.Application")

'** -> add this block here
Dim OutNS as Object
Set OutNS = OutApp.GetNamespace("MAPI")
OutNS.Logon
'**

Set OutMail = OutApp.CreateItem(0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM