我创建了一个包含日期(B2:B10)和时间(C2:C10)的2单元格。
我声明了单元格,这样它将根据单元格中的日期和时间发送电子邮件,但它显示自动化错误
Sub Send_Deferred_Mail_From_Excel()
Dim OutlookApp As Object
Dim OutlookMail As Object
Dim cell As Range
Set cell = Range("B2:C2")
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
'Send Email Using Excel VBA Macro Code
With OutlookMail
.To = "gaelvin@gmail.com"
.CC = "nickjames@gmail.com"
.BCC = ""
.Subject = "Happy New Year"
.Body = "Greeting Gael, Wish You a Very Happy New Year"
'Send email on specific date & time
.DeferredDeliveryTime = Range("B2:C2")
.Display 'or just put .Send to directly send the mail instead of display
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub
1条答案
按热度按时间roejwanj1#
DeferredDeliveryTime
接受date
作为一个值,因此需要将日期和时间合并为一个值。由于日期在VBA中的工作方式,您只需将它们添加在一起即可:
如果有机会,我还建议添加一些检查,以确保这些范围包含有效的时间和日期。