Hi Guys,
I have an Outlook VBA script that works fine for me when the attachments have different names. The script lets me select the folder to extract the attachments from then copy them into a folder.
I now have a daily email that, unfortunately has the same name in the attachment. When I run my script in the folder containing multiple daily emails, the script only extracts the latest attachment and ignores the rest of the email in the folder.
I want to modify the script to be able to download each attachment for each daily email.
The script I am using is this:
I also need each attachment to save in the folder with the 'day' i.e Monday, Tuesday etc- as the name of the attachment. e.g: 'sql report Monday'
I do not know if this can be achieved from the itm.receivedTime or the subject heading from the mail itself.
The Subject heading contains the following text: sql report results 21/03/2017 Tuesday
Obviously the day value changes daily.
The date format in the mail is: Mon 20/03/2017 00:15
I have an Outlook VBA script that works fine for me when the attachments have different names. The script lets me select the folder to extract the attachments from then copy them into a folder.
I now have a daily email that, unfortunately has the same name in the attachment. When I run my script in the folder containing multiple daily emails, the script only extracts the latest attachment and ignores the rest of the email in the folder.
I want to modify the script to be able to download each attachment for each daily email.
The script I am using is this:
Code:
Sub Shortage_Attachments()
Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim item As Object
Dim Atmt As Attachment
Dim fileName As String
Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = Application.Session.PickFolder ' Enter correct subfolder name.
On Error Resume Next
For Each item In SubFolder.Items
For Each Atmt In item.Attachments
fileName = "S:\ALL\Planning Team\Weekly Metrics\2017 Weekly_Metrics_Rebuild_V2\Weekly Metrics Reports\Clean Reports\SHORTAGE TEST\" & _
Atmt.fileName
Atmt.SaveAsFile fileName
Next Atmt
Next item
Call MsgBox("Download Complete")
End Sub
I also need each attachment to save in the folder with the 'day' i.e Monday, Tuesday etc- as the name of the attachment. e.g: 'sql report Monday'
I do not know if this can be achieved from the itm.receivedTime or the subject heading from the mail itself.
The Subject heading contains the following text: sql report results 21/03/2017 Tuesday
Obviously the day value changes daily.
The date format in the mail is: Mon 20/03/2017 00:15