2

我有一个 MS Access 数据库,我想在其中调用一个函数,该函数在字符串中包含今天的日期,如下所示。我正在尝试将今天的日期放在将要创建的新电子邮件的主题行和电子邮件正文中。有什么想法可以实现这一目标吗?

Private Sub Command_Click()

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim ThisDay As Date

ThisDay = Format(Now, "mm/dd/yy")    

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
    .To = ""
    .CC = ""
    .Subject = "Daily Email Processed " *(Thisday)
    .Body = "Hi," + vbNewLine + vbNewLine + vbNewLine + "Please find below the number of Emails processed for the  " + vbNewLine + vbNewLine + "Email Count = " + vbNewLine + "O Count = "
    .Attachments.Add ""
    .Attachments.Add ""
    .Display        
End With

Set objOutlook = Nothing

End Sub
4

1 回答 1

2

您打算在ThisDay变量 中存储一个Format()表达式。返回一个字符串,因此声明要匹配的变量。Format()

'Dim ThisDay As Date
Dim ThisDay As String

将格式化的日期字符串加载到ThisDay后,可以将其连接到主题行的其余部分。

'.Subject = "Daily Email Processed " *(Thisday)
.Subject = "Daily Email Processed " & Thisday
于 2013-02-12T07:01:35.600 回答