'VBA - Attachments doesn't save attachments automatically [closed]

i've created a vba-based script which automatically saves e-mail attachments (only PDFs) inside Outlook in specific SAN folders, depending from which e-mail address the attachment came from. After I finished the script, every time when I send a test mail, vba goes with a error message "object necessary". I'm completly stuck and I hope, some of you have a idea.

This is the script:

Public Sub saveAttachtoDisk(itm As Outlook.MailItem)
Dim objAtt As Outlook.Attachment
Dim saveFolder As String
Dim Sender As String
Set Sender = itm.SenderEmailAddress
     For Each objAtt In itm.Attachments
       If InStr(objAtt.DisplayName, ".pdf") And Sender = "[email protected]" Then
       saveFolder = "C:\Test\Ordner1\"
       objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
      End If
       If InStr(objAtt.DisplayName, ".pdf") And Sender = "[email protected]" Then
       saveFolder = "C:\Test\Ordner2\"
       objAtt.SaveAsFile saveFolder & "\" & objAtt.DisplayName
      End If
     Next
End Sub```


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source