The way to do this is to create a rule that identifies the incoming message and runs a script. The only problem is that your employer may have disabled scripts and that will need a registry change to address - https://www.slipstick.com/outlook/ru...-script-rules/. You would need to liaise with your company IT support to address that. In any case you may need to create a certificate to run Outlook code - https://www.gmayor.com/create_and_em...gital_cert.htm.
The basic code would be
If for reasons indicated, you cannot run the script from a rule then while you could create an event to process the message as required, I find that this method is less reliable and in the absence of a rule I would instead create a rule to divert the messages as they arrive into a sub folder of inbox and then select the message and run the following macro to process the message, calling the code above.Sub SaveAttachments(olItem As MailItem) 'Graham Mayor - https://www.gmayor.com - Last updated - 02 Apr 2022 Dim olAttach As Attachment Dim strFname As String Dim i As Long Const strSaveFldr As String = "D:\Path\Attachments\" 'the path where the csv is to be saved On Error Resume Next If olItem.Attachments.Count > 0 Then If InStr(1, olItem.Categories, "Processed") = 0 Then For i = 1 To olItem.Attachments.Count Set olAttach = olItem.Attachments(i) If olAttach.FileName Like "*.csv" Then strFname = olAttach.FileName olAttach.SaveAsFile strSaveFldr & strFname olItem.Categories = "Processed" Exit For End If Next i End If olItem.Save End If lbl_Exit: Set olAttach = Nothing Set olItem = Nothing Exit Sub End Sub
Sub ProcessMessage() 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 SaveAttachments olMsg lbl_Exit: Exit Sub End Sub




Reply With Quote