Sort mails based on the title of the attachment name
Hello guys
I found some vba code to move a message based on the type of attachment, but I would like to change it to the title of the attachment based on the date of today and tomorrow formatted yyymmdd.
Do you know how I could adapt the code below to do just that ? Every mail normally has just one attachment so there is no need for a loop.
The date is always on the exact same place in the attachment file name.
Sub MoveMail(Item As Outlook.MailItem)
If Item.Attachments.Count > 0 Then
Dim attCount As Long
Dim strFile As String
Dim sFileType As String
Dim sFileName As String
Dim sDateplus As String
sDateplus = Format(Date, "yyyymmdd")
sDateplus = DateAdd("dd", 1, Date)
'to check if it works
Debug.Print "date" & intDateplus
attCount = Item.Attachments.Count
For i = attCount To 1 Step -1
strFile = Item.Attachments.Item(i).FileName
'here it checks the entire attachment name with the date
sFileName = Right$(strFile, 20)
Select Case sFileName
Case "sDateplus"
' do something if the file types are found
' this code moves the message to folder attachments
Item.Move (Session.GetDefaultFolder(olattachments).Folders("Move"))
' stop checking if a match is found and exit sub
GoTo endsub
End Select
Next i
End If
Set Item = Nothing
End Sub
I have been searching a lot, but my outlook vba skills are very bad and I couldn't make it to work.
Thank you very much !