PeachyData
New Member
- Joined
- Aug 22, 2018
- Messages
- 2
Hi all
As post title states, I am trying to write some VBA code that will save & rename Outlook attachments with the attachments filename along with yesterday's date.
The attachments all have a string of 16 characters (date & time as numbers) at the end of each attachment. I wish to remove these 16 characters and replace with yesterday's date.
E.g.
Attachment filename with the 16 characters:
Expected output after running VBA:
I borrowed some code from a colleague that they use to do something similar but I have now got to the point where I need some more expert help to get this working.
Current VBA code:
Any and all help is appreciated.
Thanks for reading
Regards
As post title states, I am trying to write some VBA code that will save & rename Outlook attachments with the attachments filename along with yesterday's date.
The attachments all have a string of 16 characters (date & time as numbers) at the end of each attachment. I wish to remove these 16 characters and replace with yesterday's date.
E.g.
Attachment filename with the 16 characters:
Code:
302-AgentGroupPerformancebyAgent-2018103111482312
Expected output after running VBA:
Code:
302-AgentGroupPerformancebyAgent-301018.xls
I borrowed some code from a colleague that they use to do something similar but I have now got to the point where I need some more expert help to get this working.
Current VBA code:
Code:
Public Sub SaveDailyIndCallReportsToDisk(MItem As Outlook.MailItem)
Dim oAttachment As Outlook.Attachment
Dim sSaveFolder As String
Dim itemDate As Date
Dim sDate As String
Dim fName() As String
Dim fPath As String
Dim lPath As String
Dim dName As String
Dim FileFormatNum As Long
itemDate = MItem.CreationTime
sDate = Format(itemDate - 1, "ddmmyy")
sSaveFolder = "C:\Users\PYM\Documents\MailAttachements\"
dName = Right(MItem.Subject, -16)
If itemDate >= Date - 5 Then
For Each oAttachment In MItem.Attachments
fName = Split(oAttachment.FileName, ".")
fPath = sSaveFolder & dName & " " & sDate & "." & fName(1)
lPath = LCase(fPath)
oAttachment.SaveAsFile lPath
Next
End If
End Sub
Any and all help is appreciated.
Thanks for reading
Regards