Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Public Sub Example()
- '// Declare your Variables
- Dim olNs As Outlook.NameSpace
- Dim Inbox As Outlook.MAPIFolder
- Dim Items As Outlook.Items
- Dim Item As Outlook.MailItem
- Dim Atmt As Attachment
- Dim Filter As String
- Dim FilePath As String
- Dim AtmtName As String
- Dim i As Long
- '// Set Inbox Reference
- Set olNs = Application.GetNamespace("MAPI")
- Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
- FilePath = "C:\Temp\"
- Filter = "[attachment] = True And [Unread] = True"
- Set Items = Inbox.Items.Restrict(Filter)
- '// Loop through backwards
- For i = Items.Count To 1 Step -1
- Set Item = Items.Item(i)
- DoEvents
- If Item.Class = olMail Then
- Debug.Print Item.Subject ' Immediate Window
- For Each Atmt In Item.Attachments
- AtmtName = FilePath & Atmt.FileName
- Atmt.SaveAsFile AtmtName
- Next
- End If
- Next
- Set Inbox = Nothing
- Set Items = Nothing
- Set Item = Nothing
- Set Atmt = Nothing
- Set olNs = Nothing
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement