VBA: Create a group of Year and Month in Outlook
Sub ListSelectionYearAndMonth()
Dim aObj As Object
Dim oProp As Outlook.UserProperty
Dim sMonth
Dim sYear
On Error Resume Next
For Each aObj In Application.ActiveExplorer.Selection
Set oMail = aObj
sMonth = Month(oMail.ReceivedTime)
sYear = Year(oMail.ReceivedTime)
Set oProp = oMail.UserProperties.Add("GroupY", olText, True)
oProp.Value = sYear
Set oProp = oMail.UserProperties.Add("GroupYM", olText, True)
oProp.Value = Join(Array(sYear, "-", sMonth))
oMail.Save
Err.Clear
Next
End Sub
Last updated