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