I have a task that I need to complete for my job. I need to write a code that saves down pdf attachments from Outlook emails in a target shared drive folder. It seems easy enough I thought but unfortunately the run a script option has been disabled. I also tried to use Python but I cannot set up a task schedule as I do not have admin rights. Is there a way to copy paste a code into THisOutLookSession with the help of VBA and then run this continuously? The emails should be saved down as soon as they hit the inbox.
I tried the below code from some other post but nothing is working
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim olNs As Outlook.NameSpace
Dim Inbox As Outlook.MAPIFolder
Dim Filter As String
Filter = "@SQL=" & Chr(34) & "urn:schemas:httpmail:subject" & _
Chr(34) & " Like '%TEST%' AND " & _
Chr(34) & "urn:schemas:httpmail:hasattachment" & _
Chr(34) & "=1"
Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Set Items = Inbox.Items.Restrict(Filter)
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
Dim AtmtName As String
Dim FilePath As String
FilePath = "C:\Temp\"
Dim Atmt As Attachment
For Each Atmt In Item.Attachments
AtmtName = FilePath & Atmt.FileName
Debug.Print AtmtName ' Print on Immediate Window
Atmt.SaveAsFile AtmtName
Next
End If
End Sub