Here is an example of how you can use the ReceivedTime property in Outlook VBA to track the number of emails received yesterday:
Sub CountEmailsReceivedYesterday()
Dim inbox As Outlook.Folder
Dim items As Outlook.Items
Dim yesterdayDate As Date
Dim count As Integer
Dim email As MailItem
yesterdayDate = DateAdd("d", -1, Now())
count = 0
' Set the Inbox folder and retrieve all emails
Set inbox = Outlook.Application.Session.GetDefaultFolder(olFolderInbox)
Set items = inbox.Items
' Loop through all emails in the Inbox folder
For Each email In items
' Check if the email was received yesterday
If email.ReceivedTime >= yesterdayDate And email.ReceivedTime < Now() Then
count = count + 1
End If
Next
' Display the total count of emails received yesterday in a message box
MsgBox "Total Emails Received Yesterday: " & count
End Sub
In this code, we first set the date for yesterday using the DateAdd
function. We then retrieve the default Inbox folder and all its items using the GetDefaultFolder
method. We then loop through all the items in the folder, and for each email, we check if its ReceivedTime
property is within yesterday's date. If so, we increment the count
variable. Finally, we display the total count of emails received yesterday in a message box.
Note that this code only checks the Inbox folder. If you want to check other folders or change the time range for counting emails, you will need to modify the code accordingly.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-09 08:31:04 +0000
Seen: 8 times
Last updated: May 09 '23
What is the process to detect and count common elements in R?
How can I use Prometheus to count the number of distinct label values?
How to count relationship column in Laravel using GroupBy?
What is the total count of unique arrangements of key values that can be inserted into a hash table?
How to count the total number of exported identifiers using the eslint rule?
What is the method to execute React useEffect hook just once when there is a modification in state?
What is the method to apply two aggregation operations to lookup the same model?
What is the method for utilizing an httponly authorization cookie in an Outlook AddIn?