首页 > 解决方案 > Excel Outlook VBA:DeferredDeliveryTime:不工作

问题描述

我正在测试延迟交付时间是否有效,并查看这些电子邮件是否未发送。我在发件箱里什么也没看到。如果我只是 .Send 并注释掉 .DeferredDeliveryTime,就会发送电子邮件。此外,我已经尝试在 Outlook 中手动更改“不要提前交付”,这确实有效。所以我不确定 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

标签: excelvbaemailoutlook

解决方案


根据我的测试,你应该改变.DeferredDeliveryTime = DateAdd("n", 10, Now)位置,像这样:

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

这段代码在我的电脑上运行成功。


推荐阅读