如何在Outlook宏中使用Datediff来计算到月底为止的天数?

问题描述 投票:1回答:1

所以-写宏在Outlook中,我想计算当月剩余的天数(甚至更好的工作日)。此代码生成运行时错误5:无效的过程调用或参数。有想法吗?

Public Sub MetricsMail()
Dim MyEmail As MailItem
Dim DaysRemain As Long
Dim EndDate As Date
EndDate = DateSerial(Year(Date), Month(Date) + 1, 0)
DaysRemain = VBA.DateDiff(d, Now(), EndDate)

Set MyEmail = CreateItem(olMailItem)
With MyEmail
    .To = "Metrics"
    .Subject = Format(Now(), "mmmm dd, yyyy") & " Daily Metrics"
    .HTMLBody = DaysRemain & " Remain in this month"
End With

MyEmail.Display

End Sub
outlook-vba
1个回答
0
投票

只是一个小小的改变:

Public Sub MetricsMail()
Dim MyEmail As MailItem
Dim DaysRemain As Long
Dim EndDate As Date
EndDate = DateSerial(Year(Date), Month(Date) + 1, 0)
DaysRemain = Date()-EndDate

Set MyEmail = CreateItem(olMailItem)
With MyEmail
    .To = "Metrics"
    .Subject = Format(Now(), "mmmm dd, yyyy") & " Daily Metrics"
    .HTMLBody = DaysRemain & " Remain in this month"
End With

MyEmail.Display

End Sub

周末愉快!最大值

© www.soinside.com 2019 - 2024. All rights reserved.