PDA

View Full Version : AutoSave attachment macro issue



OllieSouth
02-20-2013, 09:58 AM
:help

Hello! Below is a VBA I use. When the rule triggers this code, a directory is created which is entitled today's date, and the attachment is saved within that folder. This worked fine when the argument was "dateFormat = Format(Now, "yyyy-mm-dd")".

Now though, I want the new directory name to be the date that the email was received, NOT today's date. This is so when I pick up these automatic reports on Monday, the reports from Saturday and Sunday don't get overwritten when they all get saved with Monday's dates.

Any tips appreciated greatly.

Thanks;
Ollie


Option Explicit
Public Sub WIBAUTOSAVEADVANCE(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim dateFormat
dateFormat = Format(MailItem.ReceivedTime, "yyyy-mm-dd")
If Len(Dir("M:\London Box Office\Daily Reports\Automation Live\Data\FORTUNE Woman in Black\" & dateFormat & "\", vbDirectory)) = 0 Then
MkDir "M:\London Box Office\Daily Reports\Automation Live\Data\FORTUNE Woman in Black\" & dateFormat & "\"
End If
saveFolder = "M:\London Box Office\Daily Reports\Automation Live\Data\FORTUNE Woman in Black\" & dateFormat & "\"
For Each objAtt In itm.Attachments
objAtt.SaveAsFile saveFolder & "\" & "ADVANCE.csv"
Set objAtt = Nothing

Next
End Sub

skatonni
02-20-2013, 02:37 PM
Try


dateFormat = Format(itm.ReceivedTime, "yyyy-mm-dd")