View Single Post
 
Old 03-01-2017, 05:58 AM
AndyDDUK AndyDDUK is offline Windows 7 64bit Office 2010 64bit
Advanced Beginner
 
Join Date: Oct 2012
Posts: 32
AndyDDUK is on a distinguished road
Default Rename attachment based on attachment name

Hi

I've receive multiple attachments on an email.

Some of these contain a date in the file name.

What is the code to modify the below, to take eg the first 5 characters in the file name?

Eg to save an attachment with a file name of "ABCDE_01032017.xls" as "ABCDE.xls" ?


Public Sub Save_APPS(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
saveFolder = "P:\Data\"


For Each objAtt In itm.Attachments

If InStr(objAtt.DisplayName, ".xls") Then

objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName

End If
Set objAtt = Nothing

Next
End Sub


May thanks
Andy
Reply With Quote