Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The following adjustment to your <strong>GetAttachments</strong> procedure will only pull attachments of <em>emails</em> from <em>John Doe</em> or if the subject contains <em>Weekly Status Report</em>.</p> <p>Please take note of the comment I have added near your file save operation. Unless you are absolutely sure that you will not encounter any duplicate file names then your should append a date stamp on to the file name or you will overwrite files each time a file with a duplicate name is saved.</p> <pre><code>Option Explicit Option Compare Text Sub GetAttachments() ' This Outlook macro checks a the Outlook Inbox for messages ' with attached files (of any type) and saves them to disk. ' NOTE: make sure the specified save folder exists before ' running the macro. On Error GoTo GetAttachments_err ' Declare variables Dim ns As NameSpace Dim Inbox As MAPIFolder Dim Item As Object Dim Atmt As attachment Dim FileName As String Dim i As Integer Set ns = GetNamespace("MAPI") Set Inbox = ns.GetDefaultFolder(olFolderInbox) i = 0 ' Check Inbox for messages and exit of none found If Inbox.Items.Count = 0 Then MsgBox "There are no messages in the Inbox.", vbInformation, _ "Nothing Found" Exit Sub End If ' Check each message for attachments For Each Item In Inbox.Items ' Save any attachments from specfic senders or subjects If TypeName(Item) = "MailItem" And (Item.SenderName = "John Doe" Or Item.Subject Like "*Weekly Status Report*") Then For Each Atmt In Item.Attachments ' This path must exist! Change folder name as necessary. FileName = "D:\New Folder\" &amp; Atmt.FileName 'CONSIDER WHETHER YOU WILL HAVE ANY FILES BY THE SAME NAME!!! Atmt.SaveAsFile FileName i = i + 1 Next Atmt End If Next Item ' Show summary message If i &gt; 0 Then MsgBox "I found " &amp; i &amp; " attached files." _ &amp; vbCrLf &amp; "I have saved them into the C:\Email Attachments folder." _ &amp; vbCrLf &amp; vbCrLf &amp; "Have a nice day.", vbInformation, "Finished!" Else MsgBox "I didn't find any attached files in your mail.", vbInformation, "Finished!" End If ' Clear memory GetAttachments_exit: Set Atmt = Nothing Set Item = Nothing Set ns = Nothing GetAttachments_exit: Exit Sub GetAttachments_err: ' Handle errors GetAttachments_err: MsgBox "An unexpected error has occurred." _ &amp; vbCrLf &amp; "Please note and report the following information." _ &amp; vbCrLf &amp; "Macro Name: GetAttachments" _ &amp; vbCrLf &amp; "Error Number: " &amp; Err.Number _ &amp; vbCrLf &amp; "Error Description: " &amp; Err.Description _ , vbCritical, "Error!" Resume GetAttachments_exit End Sub </code></pre> <p>If you need need to evaluate a large number of senders or subjects you may want to consider creating <a href="http://support.microsoft.com/kb/187234" rel="nofollow">dictionary objects</a> and checking if the email hits your criteria.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload