If you are getting the messages regularly, then you will want to automate this.
Run the first macro as a script associated with a rule that either selects messages from a specific address, or all messages as it looks for the particular attachment, which I assume will only apply to specific messages.
You can test the script by selecting a suitable message in the inbox and run the test macro.
Provided the folder and path exist the macro will save the attachment and move the message when the message arrives.
Note I have named the message to include the current month and year from the message so you don't have to edit the macro each month.
Sub SaveReport(olItem As MailItem) 'Graham Mayor - https://www.gmayor.com - Last updated - 09 Mar 2023 Dim olAttach As Attachment Dim olFolder As Folder Dim strFname As String Dim sMonth As String Dim j As Long Const strSaveName As String = '"C:\Users\ME\Documents\2023\Source Reports\Margin_" On Error Resume Next If olItem.Attachments.Count > 0 Then For j = 1 To olItem.Attachments.Count Set olAttach = olItem.Attachments(j) If LCase(olAttach.FileName) Like "*margin integrity file*" Then sMonth = Format(olItem.SentOn, "MMM_yyyy") & ".xlsb" olAttach.SaveAsFile strSaveName & sMonth Exit For End If Next j Set olFolder = Session.GetDefaultFolder(olFolderInbox).Folders("A Reports") olItem.Move olFolder End If lbl_Exit: Set olAttach = Nothing Set olItem = Nothing Set olFolder = Nothing Exit Sub End Sub Sub TestMacro() Dim olMsg As MailItem On Error Resume Next Select Case Outlook.Application.ActiveWindow.Class Case olInspector Set olMsg = ActiveInspector.currentItem Case olExplorer Set olMsg = Application.ActiveExplorer.Selection.item(1) End Select SaveReport olMsg lbl_Exit: Exit Sub End Sub




Reply With Quote