Results 1 to 12 of 12
  1. #1
    2 Star Lounger
    Join Date
    Nov 2001
    Location
    London, UK, England
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Get Outlook Folder Size (VB / Outlook 98)

    Is there a way to programmatically calculate the total size of an Outlook MAPI Folder?

    I want to be able to replicate the behavior of right mouse clicking a folder in Outlook, selecting properties and choosing 'Folder Size'.

    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get Outlook Folder Size (VB / Outlook 98)

    All (?) Outlook items (MailItem, AppointmentItem, ContactItem) have a Size property that returns the size of the item in bytes. So you could loop through the Items collection to add their sizes. The following code assumes Outlook is already active, and displays the size of the Inbox without subfolders:

    Dim olApplication As Outlook.Application
    Dim olNameSpace As Outlook.NameSpace
    Dim olFolder As Outlook.MAPIFolder
    Dim olItem
    Dim lngSize As Long
    Set olApplication = GetObject(, "Outlook.Application")
    Set olNameSpace = olApplication.GetNamespace("MAPI")
    Set olFolder = olNameSpace.GetDefaultFolder(olFolderInbox)
    For Each olItem In olFolder.Items
    lngSize = lngSize + olItem.Size
    Next olItem
    MsgBox lngSize
    Set olItem = Nothing
    Set olFolder = Nothing
    Set olNameSpace = Nothing
    Set olApplication = Nothing

    If you want to include subfolders, you would have to loop through these, and handle these recursively.

  3. #3
    2 Star Lounger
    Join Date
    Nov 2001
    Location
    London, UK, England
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get Outlook Folder Size (VB / Outlook 98)

    Thanks Hans, I was hoping there was a OutlookFolder.GetTotalSize method or something similar I had overlooked so I didn't have to write my own code...

    I suppose Microsofts 'Get Folder Size' button is simply doing what you have written, they could have been thoughtful enough to share!

    Thanks for the response.

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get Outlook Folder Size (VB / Outlook 98)

    Hi Dylan,

    The Outlook object model is much more limited than the object model for applications such as Word. It allows you to create and process Outlook items, and that's about it. There is very little you can do about the Outlook interface in code.

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Get Outlook Folder Size (VB / Outlook 98)

    Dylan,
    If you set a reference to the CDO library, you can use the MAPI fields to get the folder size - e.g.:
    <pre>Function MAPIFolderSize(fdr As MAPI.Folder)
    Const cdoPR_FOLDER_SIZE As Long = &HE08001E
    MAPIFolderSize = fdr.Fields(cdoPR_FOLDER_SIZE)
    End Function
    Sub ListAllFolders()
    Dim cdoSession As MAPI.Session, lngSize As Long
    Dim fdrMain As MAPI.Folder, fdr As MAPI.Folder
    Set cdoSession = New MAPI.Session
    cdoSession.Logon
    Set fdrMain = cdoSession.GetInfoStore.RootFolder
    For Each fdr In fdrMain.Folders
    Debug.Print fdr.Name & " size (in bytes):" & MAPIFolderSize(fdr)
    Next fdr
    Set fdrMain = Nothing
    End Sub
    </pre>

    Hope that helps.
    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get Outlook Folder Size (VB / Outlook 98)

    CDO - isn't that part of Redemption, or am I completely off? I don't know if Dylan has that...

  7. #7
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Get Outlook Folder Size (VB / Outlook 98)

    Hans,
    No, the CDO library should have been installed as part of the Outlook 98 installation. You can also download it from MS, I believe.
    HTH.
    Regards,
    Rory

    Microsoft MVP - Excel

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Get Outlook Folder Size (VB / Outlook 98)

    Rory,

    Sorry about that. You're right, it is part of Outlook 98.

  9. #9
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Get Outlook Folder Size (VB / Outlook 98)

    I admit I had to look it up to check! <img src=/S/grin.gif border=0 alt=grin width=15 height=15> I've got so much garbage installed on this machine, I've lost track of where any of it came from...
    Regards,
    Rory

    Microsoft MVP - Excel

  10. #10
    2 Star Lounger
    Join Date
    Nov 2001
    Location
    London, UK, England
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get Outlook Folder Size (VB / Outlook 98)

    Rory,

    Sounds good, but can't see that reference anywhere...do you know the name of the DLL/OLB?

    I'm halfway through writing the code using the Outlook Object Model anyway, so I'll probably stick with this - but it'll be nice to know I can use other libraries as well...

    Thanks

  11. #11
    2 Star Lounger
    Join Date
    Nov 2001
    Location
    London, UK, England
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Get Outlook Folder Size (VB / Outlook 98)

    Ignore my last post, your replies appeared while I was writing it!!

  12. #12
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Get Outlook Folder Size (VB / Outlook 98)

    Dylan,
    Depending on the number of messages involved, I think you'll find the CDO method distinctly quicker as you don't have to loop through every item in each folder. The loop may be more accurate though (whether you include the hidden messages such as views is up to you).
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

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