简体   繁体   中英

Excel Outlook VBA: DeferredDeliveryTime: Not working

I am testing if deferred delivery time works and see that these emails are not sent. I see nothing in the outbox. Emails do get sent if i just .Send and comment out .DeferredDeliveryTime. Also, I've tried manually changing Do not deliver before time in Outlook and that does work. So I am not sure what is going wrong here with the VBA.

Option Explicit

Private Sub CommandButton1_Click()

Dim olApp As Outlook.Application
Dim olMail As Outlook.MailItem
Dim olAccount As Outlook.Account

Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)

With olMail

.To = "my email"
.Subject = "test"
.Body = "test"

' .Send
 .DeferredDeliveryTime = DateAdd("n", 10, Now)
End With

End Sub

According to my test, You should change .DeferredDeliveryTime = DateAdd("n", 10, Now) Position, like this:

Dim olAccount As Outlook.Account

Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)

With olMail
.To = "email address"
.Subject = "test"
.Body = "test"
.DeferredDeliveryTime = DateAdd("n", 10, Now)
.Send

End With

End Sub

This code is run success in my PC.

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