I have a problem about a macro in VBA which, I want to use in outlook.
I have a function mailbox, and i want to verify, did i respond to the sender in the 7 days.
I made a macro, but it doesn't work. It just doesn't work on a larger scale, and i do not have any idea why.
I expect the macro to work.
Sub CheckResponses()
Dim ns As Outlook.NameSpace
Dim folder As Outlook.Folder
Dim message As Outlook.MailItem
Dim respondedOnTime As Integer
Dim noResponse As Integer
Dim startDate As Date
Dim endDate As Date
Dim titlesNoResponse As String
respondedOnTime = 0
noResponse = 0
titlesNoResponse = ""
startDate = DateSerial(2023, 1, 1)
endDate = DateSerial(2024, 1, 1)
Set ns = Application.GetNamespace("MAPI")
Set folder = ns.Folders("[email protected]").Folders("Inbox")
On Error Resume Next
For Each message In folder.Items
If message.Class = olMail And message.SentOn >= startDate And message.SentOn <= endDate Then
If message.ReceivedTime <= message.SentOn + 7 Then
If message.ReplyRecipients.Count > 0 Then
If message.ReplyRecipients(1).Address = message.SenderEmailAddress Then
respondedOnTime = respondedOnTime + 1
Else
noResponse = noResponse + 1
titlesNoResponse = titlesNoResponse & message.Subject & vbCrLf
End If
Else
noResponse = noResponse + 1
titlesNoResponse = titlesNoResponse & message.Subject & vbCrLf
End If
Else
noResponse = noResponse + 1
titlesNoResponse = titlesNoResponse & message.Subject & vbCrLf
End If
End If
Next
On Error GoTo 0
MsgBox "Responded on time to " & respondedOnTime & " messages." & vbCrLf & _
"No response: " & noResponse & vbCrLf & _
"Titles of messages without response:" & vbCrLf & titlesNoResponse, vbInformation, "Response Report"
End Sub