• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

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

  • 5
  • 4
1 Solution
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.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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:

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now