Monday, June 28, 2010

Outlook 2003 Count Folders

To count the number of mails in outlook folder wise , the below script can help you

First go to tools --> macro -->security -->set it to low

Then go to tools --> macro -->visuval basic editor

add the below code:
Dim objFile As Object
Sub CountMessages()
    Dim objFSO As Object, _
        objStore As Outlook.MAPIFolder
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Change the file name and folder on the following line as needed'
    Set objFile = objFSO.CreateTextFile("C:\eeTesting\Folder Count.txt")
    For Each objStore In Session.Folders
        objFile.WriteLine "*** Store = " & objStore.Name
        CountFolder objStore
    Set objFile = Nothing
    Set objFSO = Nothing
    MsgBox "Finished"
End Sub
Sub CountFolder(olkFolder As Outlook.MAPIFolder)
    Dim olkSubFolder As Outlook.MAPIFolder
    objFile.WriteLine olkFolder.Name & " = " & olkFolder.Items.Count
    For Each olkSubFolder In olkFolder.Folders
        CountFolder olkSubFolder
    Set olkSubFolder = Nothing
End Sub

 Then when you will run the macro from same path you will get desired result.

No comments:

Post a Comment