excel VBA在特定时间发送电子邮件-如何修复它?

6jjcrrmo  于 2022-11-18  发布在  其他
关注(0)|答案(1)|浏览(227)

我试图设置VBA在特定日期和时间发送电子邮件。但我无法正确设置此行:

.DeferredDeliveryTime

它返回运行时错误440,该对象不支持此方法。有什么想法如何修复它?
日期单元格的自定义格式为DD-MMM-YYYY,小时单元格的自定义格式为Time

Sub RectangleRoundedCorners4_Click()

Dim OutlookApplication As Object
Dim OutlookMail As Object
Dim ws As Worksheet
Dim Ads As String
Dim Subj As String
Dim Body As String
Dim DelDate As Date
Dim DelHour As Integer
Dim DelMin As Integer

    Set OutlookApplication = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApplication.CreateItem(0)
    Set ws = ActiveSheet
     Ads = ws.Cells(4, 2).Value
     Subj = ws.Cells(7, 2).Value
     Body = ws.Cells(4, 9).Value
     DelDate = ws.Cells(10, 6).Value
     DelHour = Hour(ws.Cells(12, 6).Value)
     DelMin = Minute(ws.Cells(12, 6).Value)
   

    With OutlookMail
        .To = Ads
        .CC = ""
        .BCC = ""
        .Subject = "REMINDER: " & Subj
        .Body = Body
        .DeferredDeliveryTime = DelDate & DelHour
    End With
   
    Set OutlookMail = Nothing
    Set OutlookApplication = Nothing
       
End Sub

jdzmm42g

jdzmm42g1#

DeferredDeliveryTime需要特定的日期/时间。只有连接两个值**,结果才会变成字串**。
首先,声明Dim DelHour As Date。它应该类似于02:00:00。当然,它可能包含分钟、秒,如果需要的话,应该考虑它们(02:20:30)。
然后,尝试.DeferredDeliveryTime = CDate(DelDate & " " & DelHour)
我想,这可能行得通......

相关问题