Results 1 to 1 of 1

Thread: [FAQ's OD] How do I get the number of items in a folder?

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    [FAQ's OD] How do I get the number of items in a folder?

    Just a quick example on retrieving the number of items in a given folder in a given account.
    The count is the number of items in the folder and any subfolders recursively.


    VB.NET 2002-2008 and Outlook 2000-2007

    Code:
    Option Explicit On
    Option Strict On
    'Add a COM reference to Outlook xx.0 Object Library
    Imports Microsoft.Office.Interop
    
    'Add a Button1 and TextBox1 to your form.
    Public Class Form1
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Dim oApp As Outlook.Application
                'Create an application instance
                oApp = DirectCast(CreateObject("Outlook.Application"), Outlook.Application)
                'Logon to your desired session providing the profile name and password
                oApp.Session.Logon("YouProfileNameGoesHere", Me.TextBox1.Text, False, False)
                'Display the count for the Inbox
                MessageBox.Show("Item Count: " & oApp.GetNamespace("MAPI").GetDefaultFolder( _
                                Outlook.OlDefaultFolders.olFolderInbox).Items.Count.ToString, _
                                "Count", MessageBoxButtons.OK)
                'Optionally logoff and close outlook
                'oApp.Session.Logoff()
                'oApp.Quit()
                'oApp = Nothing
            Catch ex As Exception
                MessageBox.Show(ex.Message.ToString, "Error", MessageBoxButtons.OK)
            End Try
        End Sub
    
    End Class
    Last edited by RobDog888; Jun 25th, 2008 at 02:43 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width