Rule to move attachments with specific name

Status
Not open for further replies.

Nadine

New Member
Outlook version
Outlook 2016 32 bit
Email Account
POP3
Please can someone assist me with VBA Code to create a rule for outlook to move all emails with the attachment name "SALESINVOICE" to a sub folder in my Inbox Called "Invoices". It is a pop account. Thank you.
 
The macros on Use VBA to move messages with attachments comes close to what you need - the first runs in a rule, the second checks every message that is added to the folder.

This checks for the filetype - you'll need to change it to check the filename
Code:
For i = attCount To 1 Step -1
      strFile = Item.Attachments.Item(i).FileName
      
      sFileType = LCase$(Right$(strFile, 4))
    
    Select Case sFileType
        Case ".pdf", ".doc", "docx"
    ' do something if the file types are found 
    ' this code moves the message
      Item.Move (Session.GetDefaultFolder(olFolderInbox).Folders("Invoices"))
    
   ' stop checking if a match is found and exit sub
       GoTo endsub
      End Select
  Next i



This should work but i didn't test it. I don't guarantee its error free. :) if SALESINVOICE will always be upper case, you can use it, but if the case can vary, you need to convert the subject to lower caser (or upper case) when checking. I prefer to use lcase: if instr(lcase(strfile), "salesinvoice") > 0 then

Code:
For i = attCount To 1 Step -1
      strFile = Item.Attachments.Item(i).FileName
      
if instr(strfile, "SALESINVOICE") > 0 then 
    ' do something if the file types are found 
    ' this code moves the message
      Item.Move (Session.GetDefaultFolder(olFolderInbox).Folders("Invoices"))
    
   ' stop checking if a match is found and exit sub
       GoTo endsub
end if
  Next i
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
HarvMan Outlook 365 - Rule to Move an Incoming Message to Another Folder Using Outlook 4
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1
K VBA BeforeItemMove event create rule to always move to its folder. Outlook VBA and Custom Forms 4
L Making rule to move email to folder from one O365 domain Using Outlook 1
S Send email via SMTP - use transport rules to add to senders inbox (then rule to move to sent items Exchange Server Administration 1
S How can I create a rule to move inbound emails from any of my contacts out of Inbox? Using Outlook 1
H Rule to move emails based on subject and content Outlook VBA and Custom Forms 1
B Outlook 2000 Rule to Move txt msg Not Working if size >24KB Using Outlook 3
S Creating custom rule to move if "NAME" is in body but ignore the phrase "Hi NAME" in the search Using Outlook 2
N rule to move sent mail to the deleted folder in outlook Using Outlook 4
S Rule to move messages except for replies Using Outlook 5
H move to folder rule corrupts message Using Outlook 3
A rule to move emails to a folder then want to delete them from that folder 2010 Using Outlook 5
S Rule to move BCC email to a folder Using Outlook 6
E Create Rule to Forward Email if Subject Begins With Using Outlook 2
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
B Modify VBA to create a RULE to block multiple messages Outlook VBA and Custom Forms 0
D VBA - unable to set rule condition 'on this computer only' Outlook VBA and Custom Forms 5
CWM330 This rule has a condition that the server cannot process? Using Outlook 1
A rule name into message - how? Outlook VBA and Custom Forms 5
O Mail rule issue Using Outlook 3
A manual rule sends mail to wrong folder Using Outlook 5
Aussie Outlook 365 Rule runs manually but returns the error code "an unexpected error has occurred" when incoming mail arrives Using Outlook 1
bhamberg Finding a rouge rule... Using Outlook 6
D How to get this rule to work Using Outlook 0
B Seeking help with Outlook rule Using Outlook 2
K Run a script rule to auto 'send again' on undeliverable emails? Outlook VBA and Custom Forms 1
G Save attachment run a script rule Outlook VBA and Custom Forms 0
R Rogue Outlook Rule ? Using Outlook 2
P Can I create a Rule that sends me an email when I get a Task? Using Outlook 2
E Having some trouble with a run-a-script rule (moving mail based on file type) Outlook VBA and Custom Forms 5
M How create a Rule to filter sender's email with more that one @ sign Using Outlook 1
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
1 Incorrectly Setup a Rule at Domain level to not allow address from outside domain Exchange Server Administration 2
J Transport Rule to detect Keyword question.. Exchange Server Administration 2
T "Words In Recipient's Address" Rule Causes Outlook To Stop Processing Rules Using Outlook 3
R Outlook Autoforward rule do not work for NDR messages Using Outlook 1
R Setup autofoward rule on a particular folder in Outlook Using Outlook 0
N Rule for "on behalf of" - with changing names Using Outlook 2
S Unable to remove rule outlook 2010 Using Outlook 0
O Outlook 2016 This rule will only run when you check your email in Outlook.... Using Outlook 4
N Outlook Email Rule execution through shortcut keys (VBA codes) Using Outlook 1
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
S Adding new Exchange (2016) rule very slow down Microsoft Outlook Exchange Server Administration 0
B Outlook rule run a Script doesn't work Outlook VBA and Custom Forms 1
icacream Rule based on sender / wrong sender sent to folder Using Outlook 7
Bri the Tech Guy Run Script rule not running for newly arriving messages Outlook VBA and Custom Forms 25
J Assess content of User Defined Field in Rule Using Outlook 3
A Change order of actions in one (!) rule Outlook VBA and Custom Forms 2
J HELP- Rule to auto strip prepend from external emails Using Outlook 0

Similar threads

Back
Top