Hallo Chendo,
So sollte es funktionieren:
Sub anhangAusEmailSpeichern()
'Deklaration der Variablen
Dim olApp As Object
Dim myItems As Outlook.Items
Dim myItem As Outlook.MailItem
Dim olName As Outlook.Namespace
Dim Folder As Outlook.Folder
'Counter
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim i As Integer
Dim path As String
Dim strFilter As String
Dim str As String
On Error Resume Next
'Festlegung der Objekte / Ordner
Set olApp = CreateObject("Outlook.Application")
Set olName = olApp.GetNamespace("MAPI")
'Ordner festlegen, z.B. Posteingang
Set Folder = olName.Session.Folders("xxx.xxx@xxx.com").Folders("xxx")
'Speicherort festlegen
path = "c:\test"
'Anzahl der in dem Ordner gespeicherten E-Mails ermitteln
Set myItems = Folder.Items
c = myItems.Count
'Durchlauf aller Emails
For i = myItems.Count To 1 Step -1 'Iterates from the end backwards
Set myItem = Folder.Items(i)
If Not myItem Is Nothing Then
If LCase(myItem.Subject) Like "*report*" Then
'Ermittlung der Anzahl der Attachments
a = myItem.Attachments.Count
For b = 1 To a
str = myItem.Attachments.Item(b).Filename
If LCase(str) Like "*report*" Then
myItem.Attachments.Item(b).SaveAsFile path & str
End If
Next b
End If
End If
Next i
End Sub
Viele Grüße
Kai
|