excel - 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
解决方案
根据我的测试,你应该改变.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
这段代码在我的电脑上运行成功。
推荐阅读
- java - 在 Java 中使用 Optional 和 null 检查的最佳方法是什么?
- c++ - 如何在 C++ 中使用 eigen 库导入矩阵市场文件
- javascript - 将元素值从对象数组推送到变量
- javascript - Applescript:点击带有JS的按钮
- c# - 基于windows和UWP的加解密
- ruby-on-rails - 如何检查参数/字符串是否包含子字符串?
- c# - 为什么 ListView 行会随机变得非常非常高?
- cordova - IONIC Cordova 构建永远运行
- ios - iOS 中的语音识别何时受到限制,即 requestAuthorization 返回 `SFSpeechRecognizerAuthorizationStatusRestricted`
- javascript - 使用javascript在循环属性中添加类