Here you go June7
[Sub MoveandSaveFile() Dim ns as Outlook.NameSpace Dim Folder as Outlook.folder Dim items as Outlook.items Dim item as Object Dim Attachment as Outlook.attachment Dim saveFolder as String Dim saveName as String Dim moveFolder as Outlook.folder Dim filePath as String ‘Set the save folder and file name saveFolder = “C:\Users\ME\Documents\2023\Source Reports\” saveName = “Margin_Feb_2023.xlsb” ‘get the folder containing the emails Set ns = Application.GetNameSpace(“MAPI”) Set Folder = ns.GetDefaultFolder(olFolderInbox) ‘Filter emails by Sender and Subject Set items = folder.items.Restrict (“[SenderEmailAddress] = ‘ReportScheduler@yahoo.com’ _ AND [Subject] = ‘Margin File’ “) ‘Loop through the emails For each Item in Items ‘Loop through the attachments For each attachment in Items.Attachments ‘Check if the attachment is the desired file If Attachment.FileName = “Margin Integrity File” Then ‘Save the attachment to the specified file Attachment.SaveAsFile savefolder & saveName ‘Move the email to the A Reports folder Set movefolder = ns.GetDefaultFolder(olfolderInbox).Folders(“A Reports”) item.Move movefolder ‘Set the file path and overwrite the file filePath = saveFolder & saveName Kill filepath FileCopy attachment.FileName, filePath End If Next Attachment Next Item End Sub




Reply With Quote