Dealing with PST files in VBA

G

Guest

Hello everyone,

I need to write a VBA macro to check all PST files opened within Outlook
2003 and get their size.

I got two problems (I'm new to VBA...) :

how to get the PST list...
how to get a PST file size?

Thanks for your help, Fred.
 
G

Guest

Each loaded .pst is an entry in the Namespace.Folders collection. Get one
MAPIFolder object from that collection, and you have a .pst (assuming you are
not using Exchange). Get the Folders collection from that, and you have all
the sub folders, etc.

You' have to loop through the Items collection in the entire folder
hierarchy and tabulate the Size property values for each item in order to
calculate the total folder size.

I found this code snippet lying around that could get you started:

Private Function GetFolderSize(objFolder As Outlook.MAPIFolder) As Long

Dim lngBytes As Long, intX As Integer

For intX = 1 To objFolder.Items.Count
lngBytes = lngBytes + objFolder.Items.Item(intX).Size
Next

' MsgBox "Folder size is " & lngBytes & " bytes."
GetFolderSize = lngBytes
End Function
 
G

Guest

Thanks, It is a great help...

In fact the default store is Exchange and the users have 2 or more PSTs. Is
there a property of the MapiFolder in which i could see if it is a pst or an
exchange store?

Thanks, Frederic.
 
D

Dmitry Streblechenko \(MVP\)

Two ways
1. Use Extended MAPI or Redemption to lop through the services in a profile
and retrieve the PST file names. For a Redemption sample, see
http://www.dimastr.com/redemption/profiles.htm#example2
2. Hack - loop through the folders in Namespace.Folders collection (will
return top folders of all stores) and check the store entry ids
(Folder.StoreID) - if it starts with
0000000038A1BB1005E5101AA1BB08002B2A56C2, you've got a PST provider. Convert
the store id from hex back to binary (each 2 hex chars -> 1 byte). The
resulting array will contain the full path to the PST file. Note that new
Unicode PST store in Outlook 2003 uses Unicode rather than ANSI for the
path.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top