Sub SaveAttachmentsToDiskRule(Item As Outlook.MailItem)
'Change the path on the next line to the folder you want the attachments save to. The path must end with a backslash.'
Const SAVE_TO_PATH = "C:\Some Folder\August 2009\"
Dim olkAttachment As Outlook.Attachment, _
strSubfolder As String, _
strFilename As String, _
objFSO As Object, _
arrParts As Variant
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each olkAttachment In Item.Attachments
If objFSO.GetExtensionName(LCase(olkAttachment.FileName)) = "xls" Then
arrParts = Split(olkAttachment.FileName, "_")
If UBound(arrParts) = 4 Then
'Add other cases as needed'
Select Case arrParts(1)
Case "NC0136065"
strSubfolder = SAVE_TO_PATH & "0136065 James\"
Case "NC0564454"
strSubfolder = SAVE_TO_PATH & "0564454 Man\"
Case Else
strSubfolder = ""
End Select
strFilename = olkAttachment.FileName
intCount = 0
Do While True
If Dir(strSubfolder & strFilename) = "" Then
Exit Do
Else
intCount = intCount + 1
'Edit the file name format on the next line as desired'
strFilename = "Copy (" & intCount & ") of " & olkAttachment.FileName
End If
Loop
olkAttachment.SaveAsFile strSubfolder & strFilename
End If
End If
Next
Set objFSO = Nothing
Set olkAttachment = Nothing
End Sub
|