Downloading Attachments from Unread Emails of MS Outlook
<p>I want to download all attachments of Unread emails from my MS Outlook. I found this below mentioned code on <strong>StackExchange</strong> which downloads attachments from first Unread email. </p>

<p>Can any one modify this code so i can apply it on all Unread emails.</p>

<pre><code>Const olFolderInbox As Integer = 6
'~~&gt; Path for the attachment
Const AttachmentPath As String = "C:\"

Sub DownloadAttachmentFirstUnreadEmail()
    Dim oOlAp As Object, oOlns As Object, oOlInb As Object
    Dim oOlItm As Object, oOlAtch As Object

    '~~&gt; New File Name for the attachment
    Dim NewFileName As String
    NewFileName = AttachmentPath &amp; Format(Date, "DD-MM-YYYY") &amp; "-"

    '~~&gt; Get Outlook instance
    Set oOlAp = GetObject(, "Outlook.application")
    Set oOlns = oOlAp.GetNamespace("MAPI")
    Set oOlInb = oOlns.GetDefaultFolder(olFolderInbox)

    '~~&gt; Check if there are any actual unread emails
    If oOlInb.Items.Restrict("[UnRead] = True").Count = 0 Then
        MsgBox "NO Unread Email In Inbox"
        Exit Sub
    End If

    '~~&gt; Extract the attachment from the 1st unread email
    For Each oOlItm In oOlInb.Items.Restrict("[UnRead] = True")
        '~~&gt; Check if the email actually has an attachment
        If oOlItm.Attachments.Count &lt;&gt; 0 Then
            For Each oOlAtch In oOlItm.Attachments
                '~~&gt; Download the attachment
                oOlAtch.SaveAsFile NewFileName &amp; oOlAtch.Filename
                Exit For
            Next
        Else
            MsgBox "The First item doesn't have an attachment"
        End If
        Exit For
    Next
 End Sub
</code></pre>