Wednesday, July 11, 2018

email - Using ReceivedTime in Outlook VBA to count yesterday's mail

I want to flash up a message box with the amount of mail received yesterday.



The code I have at the moment is:



Public Sub YesterdayCount()

Set ns = Application.GetNamespace("MAPI")
Set outApp = CreateObject("Outlook.Application")

Set outNS = outApp.GetNamespace("MAPI")

Dim Items As Outlook.Items
Dim MailItem As Object

Dim yestcount As Integer
yestcount = 0

Set Folder = outNS.Folders("Correspondence Debt Advisor Queries").Folders("Inbox")
Set Items = Folder.Items


For Each Item In Items
If MailItem.ReceivedTime = (Date - 1) Then
yestcount = yestcount + 1
End If
Next

MsgBox yestcount

End Sub



The problem is with the line:



If MailItem.ReceivedTime = (Date - 1) Then


The error says that an object variable is not set, but I can't fathom this after researching.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...