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

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???

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David LeeCommented:
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

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

David LeeCommented:

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

kdunnettAuthor Commented:
Thanks man this is excellent
David LeeCommented:
You're welcome.
kdunnettAuthor Commented:
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>

David LeeCommented:
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.
kdunnettAuthor Commented:

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

David LeeCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.