我想要做的只是在以下代码中在VBA中设置日期变量。但是,如果我尝试使用mydate = date,它就不起作用:
Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim mydate As String
mydate = date
saveFolder = "T:\EC Portfolio Reports\CCA Credit Europe\ctpty"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & mydate & objAtt.FileName
Set objAtt = Nothing
Next
End Sub
答案 0 :(得分:1)
将日期作为字符串,使用format
。这也允许您删除日期中的任何非法字符,因为date
将返回斜杠 - 文件名不能包含 /:*?“<> |
使用mydate = format(date,"yyyymmdd")