0

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

1 Answers1

1

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")

SeanC
  • 15,695
  • 5
  • 45
  • 66