Generating a list of entryids under the "all Public Folders" tree

Posted on 2006-03-22
Last Modified: 2010-04-08
I require a way of generating a list of all entryids with folder name and path for all folders listed under the "all Public Folders" tree from outlook to a file.  Does anybody have a tool or a piece of code to do this???

Question by:kdunnett
    LVL 76

    Expert Comment

    by:David Lee
    Greetings, kdunnett.

    This will do it.  Let me know if you need instuctions on how to run this from inside Outlook.

    'Code Begins Here
    Dim objFSO As Object, _
        objFile As Object

    Sub DumpEntryIDs()
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        'Change the file name and path on the following line
        Set objFile = objFSO.CreateTextFile("C:\eeTesting\EntryIDs.txt")
        ProcessFolder OpenMAPIFolder("\Public Folders\All Public Folders")
        Set objFile = Nothing
        Set objFSO = Nothing
        MsgBox "All done!"
    End Sub

    Sub ProcessFolder(olkFolder As Outlook.MAPIFolder)
        Dim olkSubFolder As Outlook.MAPIFolder
        With olkFolder
            objFile.WriteLine .EntryID & vbTab & Pad(.Name, 25) & .FolderPath
        End With
        For Each olkSubFolder In olkFolder.Folders
            ProcessFolder olkSubFolder
        Set olkSubFolder = Nothing
    End Sub

    Function Pad(strValue As String, intLength As Integer) As String
        Dim intValueLength As Integer
        intValueLength = Len(Trim(strValue))
        If intValueLength < intLength Then
            Pad = Trim(strValue) & Space(intLength - intValueLength)
            Pad = strValue
        End If
    End Function

    'Credit where credit is due.
    'The code below is not mine.  I found it somewhere on the internet but do
    'not remember where or who the author is.  The original author(s) deserves all
    'the credit for these functions.
    Function OpenMAPIFolder(szPath)
        Dim app, ns, flr, szDir, i
        Set flr = Nothing
        Set app = CreateObject("Outlook.Application")
        If Left(szPath, Len("\")) = "\" Then
            szPath = Mid(szPath, Len("\") + 1)
            Set flr = app.ActiveExplorer.CurrentFolder
        End If
        While szPath <> ""
            i = InStr(szPath, "\")
            If i Then
                szDir = Left(szPath, i - 1)
                szPath = Mid(szPath, i + Len("\"))
                szDir = szPath
                szPath = ""
            End If
            If IsNothing(flr) Then
                Set ns = app.GetNamespace("MAPI")
                Set flr = ns.Folders(szDir)
                Set flr = flr.Folders(szDir)
            End If
        Set OpenMAPIFolder = flr
    End Function

    Function IsNothing(obj)
      If TypeName(obj) = "Nothing" Then
        IsNothing = True
        IsNothing = False
      End If
    End Function
    'Code Ends Here


    Author Comment

    Excellent example, any instructions you have would be great as I’m new to outlook.

    LVL 76

    Accepted Solution


    1.  Open Outlook.
    2.  Click Tools->Macro->Visual Basic Editor.
    3.  If it's not already expanded, expand Modules and click on Module1.
    4.  Copy the code I posted and paste it into the right-hand pane of the Visual Basic Editor.
    5.  Click the diskette icon to save the change.
    6.  Exit the Visual Basic Editor.
    7.  Click Tools->Macro->Security.
    8.  Change the Security Level to Medium.

    Author Comment

    Thanks man this is excellent
    LVL 76

    Expert Comment

    by:David Lee
    You're welcome.

    Author Comment

    Is there a way I could add the size of the outlook public folder to the log file using the above code?

    objFile.WriteLine .EntryID & vbTab & Pad(.Name, 25) & .FolderPath & vbTab & <FOLDER SIZE>

    LVL 76

    Expert Comment

    by:David Lee
    The Folder object doesn't have a size property.  The only way to calculate the size would be to loop through all the items in the folder and add the size up.

    Author Comment


    If I was to create a new question could you come up with some code to return the size of each folder

    LVL 76

    Expert Comment

    by:David Lee

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Create high volume marketing opportunities using email signatures with these top 10 DOs and DON'Ts of email signature marketing.
    Outlook Free & Paid Tools
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now