Note: The other languages of the website are Google-translated. Back to English

How to classify the emails by month in Outlook?

If there are lots of emails in your Inbox, to make the mailbox look neat and well-organized, you can store or archive them into different folders based on the specific month of the emails’ received time as below screenshot shown. Normally, you can create the folders manually and then move them one by one. Obviously, this approach will be time-consuming and troublesome. In this article, I will talk about a VBA code for solving this task quickly and easily.

Classify the emails based on month with VBA code

To move the emails to different folders based on month, please apply the below VBA code:

1. Click to select the Inbox folder that you want to classify the emails.

2. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Classify the emails based on month

Sub ClassifyEmailsbyMonth()
'Updateby ExtendOffice
Dim xCurFolder As Folder
Dim xMoveFolder As Folder
Dim xMail As MailItem
Dim I As Long
Dim xYear As String, xMonth As String
On Error Resume Next
Set xCurFolder = Application.ActiveExplorer.CurrentFolder
For I = xCurFolder.Items.Count To 1 Step -1
  If xCurFolder.Items.Item(I).Class = olMail Then
    Set xMail = xCurFolder.Items.Item(I)
    xYear = Year(xMail.ReceivedTime)
    xMonth = Month(xMail.ReceivedTime)
    Set xMoveFolder = Nothing
    Set xMoveFolder = xCurFolder.Folders(xYear & "." & xMonth)
    If xMoveFolder Is Nothing Then
      Set xMoveFolder = xCurFolder.Folders.Add(xYear & "." & xMonth)
    End If
    xMail.Move xMoveFolder
  End If
Set xMoveFolder = Nothing
Set xCurFolder = Nothing
End Sub

4. Then, press F5 key to execute this code, and all the emails in the selected Inbox folder are classified by specific month of the emails’ received time, see screenshot:

Kutools for Outlook - Brings 100 Advanced Features to Outlook, and Make Work Much Easier!

  • Auto CC/BCC by rules when sending email; Auto Forward Multiple Emails by custom; Auto Reply without exchange server, and more automatic features...
  • BCC Warning - show message when you try to reply all if your mail address is in the BCC list; Remind When Missing Attachments, and more remind features...
  • Reply (All) With All Attachments in the mail conversation; Reply Many Emails in seconds; Auto Add Greeting when reply; Add Date into subject...
  • Attachment Tools: Manage All Attachments in All Mails, Auto Detach, Compress All, Rename All, Save All... Quick Report, Count Selected Mails...
  • Powerful Junk Emails by custom; Remove Duplicate Mails and Contacts... Enable you to do smarter, faster and better in Outlook.
shot kutools outlook kutools tab 1180x121
shot kutools outlook kutools plus tab 1180x121
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Leave your comments
Posting as Guest
Rate this post:
0   Characters
Suggested Locations