Micro Focus QTP (UFT) Forums
Script to count the number of mails in a given folder in Outlook - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Script to count the number of mails in a given folder in Outlook (/Thread-Script-to-count-the-number-of-mails-in-a-given-folder-in-Outlook)



Script to count the number of mails in a given folder in Outlook - Sudhamshu - 10-10-2009

Hi, I have written the Script to count the number of mails in a given folder in Outlook as like this.

Code:
Set olApp = CreateObject("Outlook.Application")
Set olns = olApp.GetNameSpace("MAPI")
Set Folder = olns.GetDefaultFolder(3)
msgbox Folder.Items.Count

but my doubt is, I want to check the count of not the default folders of the Outlook, where as I need to count all the mails in my Personal folders too.

How can I change my code?

Thanks in Advance.


RE: Script to count the number of mails in a given folder in Outlook - Saket - 10-10-2009

use a loop to go through all the folders, and find your personal folder.
see the code below
Code:
Set olApp = CreateObject("Outlook.Application")
Set olns = olApp.GetNameSpace("MAPI")
    For icnt = 1 To olns.Folders.Count
        If UCase(ns.Folders.Item(icnt)) = "<<YOUR PERSONAL FOLDER>>" Then '
            Set Folder = olns.Folders.Item(icnt)
            Exit For
        End If
    Next
msgbox Folder.Items.Count



RE: Script to count the number of mails in a given folder in Outlook - Sudhamshu - 10-12-2009

Thanks Saketh, it is working now