Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8484949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:30:35+00:00 2026-06-10T20:30:35+00:00

I need a rule (or most probably a VBA macro) to sort my mails.

  • 0

I need a rule (or most probably a VBA macro) to sort my mails. In case I have per say “REPORT” in the filename of the attachment of a newly received mail than I would like to move that mail to a different folder, let say “REPORTS” folder.

How can I achieve this?

I already to set a rule on the mail header but that did not seem to solve the matter.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:30:37+00:00Added an answer on June 10, 2026 at 8:30 pm

    Used code from http://www.outlookcode.com/article.aspx?id=62 and http://blog.saieva.com/2010/03/27/move-messages-to-folders-with-outlook-vba/

    'code goes in "ThisOutlookSession" module
    Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
        Dim arr() As String
        Dim i As Integer
        Dim ns As Outlook.NameSpace
        Dim itm As MailItem
        Dim m As Outlook.MailItem
        Dim att As Outlook.Attachment
    
        On Error Resume Next
        Set ns = Application.Session
        arr = Split(EntryIDCollection, ",")
        For i = 0 To UBound(arr)
            Set itm = ns.GetItemFromID(arr(i))
            If itm.Class = olMail Then
                Set m = itm
                If m.Attachments.Count > 0 Then
                    For Each att In m.Attachments
                        If UCase(att.FileName) Like "*REPORT*" Then
                            MoveToFolder m, "MoveTest"
                            Exit For
                        End If
                    Next att
                End If
            End If
        Next
        Set ns = Nothing
        Set itm = Nothing
        Set m = Nothing
    End Sub
    
    
    Sub MoveToFolder(mItem As MailItem, folderName)
    
     '###you need to edit this for your account name###
     Const mailboxNameString As String = "Mailbox - firstname lastname"
    
     Dim olApp As New Outlook.Application
     Dim olNameSpace As Outlook.NameSpace
     Dim olDestFolder As Outlook.MAPIFolder
    
     Set olNameSpace = olApp.GetNamespace("MAPI")
     Set olDestFolder = olNameSpace.Folders(mailboxNameString).Folders(folderName)
    
     Debug.Print "[" & Date & " " & Time & "] " & _
                    ": folder = " & folderName & _
                    "; subject = " & mItem.Subject & "..."
    
     mItem.Move olDestFolder
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following rewrite rule that I need to alter in order to
Do I even need this rule anymore? I don't see any requests incoming for
I'm struggling with a css selector. I need a css rule that returns all
I need to build a rule-based system that can be run and developed in
I need to add a rule in the firewall so that my self-hosted http
I need to create a special makefile rule, which is best explained by an
I need to do a 2 rule replace -- my rules are, replace all
I need a little help figuring out what the following URL rewrite rule means.
Is there a rule regarding which statements don't need to be terminated with a
I need some advice, what is the rule of the thumb when creating Rails

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.