JonasAdamski
New Member
- Joined
- Feb 1, 2022
- Messages
- 7
- Office Version
- 2010
- Platform
- Windows
Hi Guys,
I want to get the number of emails in specific folders (multiple folders, 7 to be exact), I am not worried about the date or month. But a count of the emails in these folders is enough.
I also want the date of the last email in these sub folders. The folder is a shared folder that many employees have just like I do and we are supposed to process the data from this shared folder in Outlook.
Could someone please help me because I don't seem to make any progress. Thanks and have a nice day
I have found this code for now, but it only counts the number of emails in a specific folder and not in multiple folders. Also this does not give the date of the last email to me.
Sub count()
Dim objItems As Outlook.Items
Dim objItem As Object
Dim objMail As Outlook.MailItem
Dim strMonth As String
Dim dReceivedTime As Date
Dim strReceivedDate As String
Dim i, n As Long
Dim strMsg As String
Dim nPrompt As Integer
Dim NS As NameSpace
Dim folder As MAPIFolder
Set NS = Application.GetNamespace("MAPI")
Set folder = NS.Folders("abcgmail.com").Folders("Inbox") '.Folders("Subfolder").Folders("Subfolder")
Set objItems = folder.Items
'Set objItems = Outlook.Application.Posteingang
objItems.SetColumns ("ReceivedTime")
strMonth = InputBox("Enter the specific month.(Format: yyyy)", "Specify year")
If strMonth <> "" Then
n = 0
For i = 1 To objItems.count
If objItems.Item(i).Class = olMail Then
Set objMail = objItems.Item(i)
dReceivedTime = objMail.ReceivedTime
strReceivedDate = Format(dReceivedTime, "yyyy")
If strReceivedDate = strMonth Then
n = n + 1
End If
End If
Next i
strMsg = "You have received " & n & " emails on " & strMonth & "."
nPrompt = MsgBox(strMsg, vbExclamation, "Count Received Emails")
Else
nPrompt = MsgBox("Please input the specific day!", vbExclamation)
End If
End Sub
I want to get the number of emails in specific folders (multiple folders, 7 to be exact), I am not worried about the date or month. But a count of the emails in these folders is enough.
I also want the date of the last email in these sub folders. The folder is a shared folder that many employees have just like I do and we are supposed to process the data from this shared folder in Outlook.
Could someone please help me because I don't seem to make any progress. Thanks and have a nice day
I have found this code for now, but it only counts the number of emails in a specific folder and not in multiple folders. Also this does not give the date of the last email to me.
Sub count()
Dim objItems As Outlook.Items
Dim objItem As Object
Dim objMail As Outlook.MailItem
Dim strMonth As String
Dim dReceivedTime As Date
Dim strReceivedDate As String
Dim i, n As Long
Dim strMsg As String
Dim nPrompt As Integer
Dim NS As NameSpace
Dim folder As MAPIFolder
Set NS = Application.GetNamespace("MAPI")
Set folder = NS.Folders("abcgmail.com").Folders("Inbox") '.Folders("Subfolder").Folders("Subfolder")
Set objItems = folder.Items
'Set objItems = Outlook.Application.Posteingang
objItems.SetColumns ("ReceivedTime")
strMonth = InputBox("Enter the specific month.(Format: yyyy)", "Specify year")
If strMonth <> "" Then
n = 0
For i = 1 To objItems.count
If objItems.Item(i).Class = olMail Then
Set objMail = objItems.Item(i)
dReceivedTime = objMail.ReceivedTime
strReceivedDate = Format(dReceivedTime, "yyyy")
If strReceivedDate = strMonth Then
n = n + 1
End If
End If
Next i
strMsg = "You have received " & n & " emails on " & strMonth & "."
nPrompt = MsgBox(strMsg, vbExclamation, "Count Received Emails")
Else
nPrompt = MsgBox("Please input the specific day!", vbExclamation)
End If
End Sub