使用文件名中的日期保存Outlook附件 [英] Saving Outlook attachment with date in the filename
本文介绍了使用文件名中的日期保存Outlook附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要做的就是非常简单地在下面的代码中在VBA中设置一个日期变量.但是,如果我尝试使用mydate = date,则无法使用:
All I want to do is very simply set a date variable in VBA in the following code. However if I try to use mydate = date, it doesn't work:
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
推荐答案
要将日期作为字符串,请使用format
.这也将允许您删除日期中的任何非法字符,因为date
将返回斜杠-文件名不能包含/:*?<> |
to have the date as a string, use format
. This will also allow you to remove any illegal characters in the date, as date
will return slashes - Filenames cannot contain /:*?"<>|
使用mydate = format(date,"yyyymmdd")
这篇关于使用文件名中的日期保存Outlook附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文