Hi, I have some mailboxes in my Outlook, from where I need to count the total number of mails, the mails older than 30 days, and to get the date of the oldest email.
After that I need to put in these numbers in a excel sheet.
I have the following VBA code, that gets me the total number of emails and outputs the result to excel.
The problem is that I have no idea on how to get the number of emails older than 30 days, or the date of the oldest email.
Ideally, I would need a count of the number of attachments in the mailbox (also the number of attachments from emails older than 30 days).
At this moment, I estimate the number of attachments based on the email count.
Thank you!
After that I need to put in these numbers in a excel sheet.
I have the following VBA code, that gets me the total number of emails and outputs the result to excel.
The problem is that I have no idea on how to get the number of emails older than 30 days, or the date of the oldest email.
Code:
Sub HowManyEmails()
Dim objOutlook As Object, objnSpace As Object, objFolder As MAPIFolder
Dim EmailCount As Integer
Set objOutlook = CreateObject("Outlook.Application")
Set objnSpace = objOutlook.GetNamespace("MAPI")
On Error Resume Next
Set objFolder1 = objnSpace.Folders("email@email.com").Folders("test")
Set objFolder2 = objnSpace.Folders("email_2@email.com").Folders("Inbox")
If Err.Number <> 0 Then
Err.Clear
MsgBox "No such folder."
Exit Sub
End If
EmailCount1 = objFolder1.Items.Count
EmailCount2 = objFolder2.Items.Count
Sheets("Sheet1").Range("B2").Value = EmailCount1
Sheets("Sheet1").Range("B3").Value = EmailCount2
Set objFolder = Nothing
Set objnSpace = Nothing
Set objOutlook = Nothing
End Sub
Ideally, I would need a count of the number of attachments in the mailbox (also the number of attachments from emails older than 30 days).
At this moment, I estimate the number of attachments based on the email count.
Thank you!