Question : MS Outlook - Count emails

Hi Experts

Is there a way of counting the number of emails a specific mailbox in our cokpnay receives daily. Is there a way to get some sort of report or some way of running a command that adds the number of emais. Maybe even getting this report or count emailed to another user daily.

Answer : MS Outlook - Count emails

Here's the code for counting up the items.  Follow these instructions to add it to Outlook.

Outlook 2003

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of
5.  Outlook's VB Editor window
6.  Edit the code as needed.  I included comment lines wherever something needs to or can change
7.  Click the diskette icon on the toolbar to save the changes
8.  Close the VB Editor
9.  Click Tools > Macro > Security
10. Set the Security Level to Medium
11. Close Outlook
12. Start Outlook
13. Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.

Outlook 2007

1.  Start Outlook
2.  Click Tools > Macro > Visual Basic Editor
3.  If not already expanded, expand Microsoft Office Outlook Objects and click on ThisOutlookSession
4.  Copy the code from the Code Snippet box and paste it into the right-hand pane of Outlook's VB Editor window
5.  Edit the code as needed.  I included comment lines wherever something needs to or can change
6.  Click the diskette icon on the toolbar to save the changes
7.  Close the VB Editor
8.  Click Tools > Trust Center
9.  Click Macro Security
10. Set Macro Security to "Warnings for all macros"
11. Click OK
12. Close Outlook
13. Start Outlook.  Outlook will display a dialog-box warning that ThisOutlookSession contains macros and asking if you want to allow them to run.  Say yes.

Once you have the code in place and we know it's counting the items, then I'll post the code for retrieving the count.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
Dim WithEvents olkInbox As Outlook.Items

Private Sub Application_Quit()
    Set olkInbox = Nothing
End Sub

Private Sub Application_Startup()
    Set olkInbox = Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub olkInbox_ItemAdd(ByVal Item As Object)
    If Item.Class = olMail Then
        Add2Count
    End If
End Sub

Sub Add2Count()
    'Edit the path on the next line'
    Const FILE_PATH = "c:\Users\David\Documents\"
    Dim objFSO As Object, objFile As Object, lngCounter As Long, strDate As String
    lngCounter = 0
    strDate = Format(Date, "yyyy-mm-dd")
    Set objFSO = CreateObject("Scripting.FileSystemobject")
    If objFSO.FileExists(FILE_PATH & strDate & ".txt") Then
        Set objFile = objFSO.OpenTextFile(FILE_PATH & strDate & ".txt", ForReading)
        lngCounter = objFile.ReadAll
    Else
        Set objFile = objFSO.CreateTextFile(FILE_PATH & strDate & ".txt")
    End If
    objFile.Close
    lngCounter = lngCounter + 1
    Set objFile = objFSO.CreateTextFile(FILE_PATH & strDate & ".txt")
    objFile.Write lngCounter
    objFile.Close
    Set objFile = Nothing
    Set objFSO = Nothing
End Sub
Random Solutions  
 
programming4us programming4us