简体   繁体   中英

Saving Outlook attachment with date in the filename

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

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 /:*?"<>|

use mydate = format(date,"yyyymmdd")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM