L
Lars
Hello,
I need to have the folder size of a personal folder (pst)
I've already implemented a simple (but slow) solution, may there is a better
function already included in the outlook objects ?
How does it works on "properties" -> "folder size" ? It seams to be faster.
Public Sub FolderCleanUp()
Dim FolderSize As Long
Dim myOlApp As Outlook.Application 'Outlook-Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
'Scan all folders
For Each myFolder In myNameSpace.Folders
'Determine Size of all elements in this folder incl. sub-folders
FolderSize = DetermineSize(myFolder)
Debug.Print (myFolder.Name & vbCrLf & _
" " & ShowSize(FolderSize))
NextFor:
Next myFolder
End Sub
' Rekursive Funktion zur Bestimmung der Größe aller Objekte in einem Ordner
(inkl. Unterordner)
Private Function DetermineSize(objFolder As MAPIFolder) As Long
Dim i As Long
DetermineSize = 0
'Die Größe der Objekte im Ordner addieren (Items)
For i = 1 To objFolder.Items.Count
DetermineSize = DetermineSize + objFolder.Items.Item(i).Size
Next i
'Die Unterordner nun auch noch durchsuchen (Folder)
For i = 1 To objFolder.Folders.Count
DetermineSize = DetermineSize + DetermineSize(objFolder.Folders.Item(i))
Next i
End Function
I need to have the folder size of a personal folder (pst)
I've already implemented a simple (but slow) solution, may there is a better
function already included in the outlook objects ?
How does it works on "properties" -> "folder size" ? It seams to be faster.
Public Sub FolderCleanUp()
Dim FolderSize As Long
Dim myOlApp As Outlook.Application 'Outlook-Application
Dim myNameSpace As Outlook.NameSpace
Dim myFolder As Outlook.MAPIFolder
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
'Scan all folders
For Each myFolder In myNameSpace.Folders
'Determine Size of all elements in this folder incl. sub-folders
FolderSize = DetermineSize(myFolder)
Debug.Print (myFolder.Name & vbCrLf & _
" " & ShowSize(FolderSize))
NextFor:
Next myFolder
End Sub
' Rekursive Funktion zur Bestimmung der Größe aller Objekte in einem Ordner
(inkl. Unterordner)
Private Function DetermineSize(objFolder As MAPIFolder) As Long
Dim i As Long
DetermineSize = 0
'Die Größe der Objekte im Ordner addieren (Items)
For i = 1 To objFolder.Items.Count
DetermineSize = DetermineSize + objFolder.Items.Item(i).Size
Next i
'Die Unterordner nun auch noch durchsuchen (Folder)
For i = 1 To objFolder.Folders.Count
DetermineSize = DetermineSize + DetermineSize(objFolder.Folders.Item(i))
Next i
End Function