user1149620
user1149620

Reputation: 873

Count Emails In Inbox Every Hour And Save To text file

I'm trying to write some VBA in Outlook to count emails in the inbox folder (unread and read) every hour and to dump something like the below to a text file each time that happens:

28/02/2018 01:00 - 1,320

I've seen various code snippets, but I'm not sure how to achieve this. Could someone help please?

Upvotes: 0

Views: 487

Answers (1)

0m3r
0m3r

Reputation: 12499

Should be simple to do that-

Example

Option Explicit
Public Sub example()
    Dim Items As Outlook.Items
    Set Items = Application.Session.GetDefaultFolder( _
                                    olFolderInbox).Items

    Debug.Print Now() & " - " & Items.Count

    Dim FSO As New FileSystemObject
    Dim TS As TextStream
    Set TS = FSO.OpenTextFile("C:\Temp\Emails_Count.txt", ForAppending, True)
        TS.Write Now() & " - " & Items.Count
        TS.Close
End Sub

enter image description here

Upvotes: 1

Related Questions