G
Greg J
Hi,
I am trialling some code in Outlook VBA to see how fast I can read
through all items in a mailbox to get the current size. I have done
this successfully with the Outlook Object Model but have heard/read
that MAPI is much faster. The following code IS much faster and works
mostly but there are some Outlook items it simply refuses to read and
therefore I cannot get an accurate size of the Mailbox. The mailbox I
am using does not have a full compliment of all available item classes
but the list below is what I have uncovered so far.
I am working with Outlook 2003 and Exchange 2003. The error I receive
is -2147024891 [Collaboration Data Objects -
[E_ACCESSDENIED(80070005)]]
Errors Occur for Outlook Object Model Item Classes:
- MessageClass = IPM.Schedule.Meeting.Request (olMeetingRequest = 53)
- MessageClass = IPM.Schedule.Meeting.Canceled (olMeetingCancellation
= 54)
- MessageClass = IPM.Schedule.Meeting.Resp.Neg
(olMeetingResponseNegative = 55)
- MessageClass = IPM.Schedule.Meeting.Resp.Pos
(olMeetingResponsePositive = 56)
- MessageClass = IPM.Schedule.Meeting.Resp.Tent
(olMeetingResponseTentative = 57)
The error occurs on the line where I try to assign an item in the
MAPI.Messages collection to an Object variable, ie: Set Obj =
mpMsgs.Item(i)
Any ideas as to how I can read these items would be greatly
appreciated.
'Main function to find the Root folder for the Mailbox and initiate
enumeration of folders
Function MapiSizeCheck()
Dim mpSess As MAPI.Session
Dim mpRoot As MAPI.Folder
Dim strStoreID As String
Set mpSess = New MAPI.Session
mpSess.Logon "Outlook"
'Get the Store ID for the main Exchange mailbox
strStoreID =
mpSess.GetDefaultFolder(CdoDefaultFolderInbox).StoreID
'Get the root folder (IPM_SUBTREE) for the Exchange Mailbox
Set mpRoot = mpSess.GetInfoStore(strStoreID).RootFolder
'Initiate enumeration of the folders
fnGetFolderSizes mpRoot
'Clean up
Set mpRoot = Nothing
mpSess.Logoff
Set mpSess = Nothing
End Function
'Recursive function to read enumerate each Folder MAPI.Messages
collection
Function fnGetFolderSizes(mpFdr As MAPI.Folder)
On Error Resume Next
Dim mpSub As MAPI.Folder
Dim mpMsgs As MAPI.Messages
Dim Obj As Object
'Get the collection of items in the folder
Set mpMsgs = mpFdr.Messages
lngCount = mpMsgs.Count
'Get the item details if items exist
If lngCount > 0 Then
'Enumerate the items in the collection to get each items
details (class, size etc)
For i = 1 To mpMsgs.Count
'ERROR OCCURS ON THIS NEXT LINE
Set Obj = mpMsgs.Item(i)
'ERROR! -2147024891 [Collaboration Data Objects -
[E_ACCESSDENIED(80070005)]]
'do stuff with item here...
Next
End If
'If the folder has sub-folders, call this procedure for the sub-
folder
If mpFdr.Fields(CdoPR_SUBFOLDERS) Then
For Each mpSub In mpFdr.Folders
fnGetFolderSizes mpSub
Next
End If
'Cleanup
Set Obj = Nothing
Set mpMsgs = Nothing
Set mpSub = Nothing
End Function
Regards
Greg Johncock
I am trialling some code in Outlook VBA to see how fast I can read
through all items in a mailbox to get the current size. I have done
this successfully with the Outlook Object Model but have heard/read
that MAPI is much faster. The following code IS much faster and works
mostly but there are some Outlook items it simply refuses to read and
therefore I cannot get an accurate size of the Mailbox. The mailbox I
am using does not have a full compliment of all available item classes
but the list below is what I have uncovered so far.
I am working with Outlook 2003 and Exchange 2003. The error I receive
is -2147024891 [Collaboration Data Objects -
[E_ACCESSDENIED(80070005)]]
Errors Occur for Outlook Object Model Item Classes:
- MessageClass = IPM.Schedule.Meeting.Request (olMeetingRequest = 53)
- MessageClass = IPM.Schedule.Meeting.Canceled (olMeetingCancellation
= 54)
- MessageClass = IPM.Schedule.Meeting.Resp.Neg
(olMeetingResponseNegative = 55)
- MessageClass = IPM.Schedule.Meeting.Resp.Pos
(olMeetingResponsePositive = 56)
- MessageClass = IPM.Schedule.Meeting.Resp.Tent
(olMeetingResponseTentative = 57)
The error occurs on the line where I try to assign an item in the
MAPI.Messages collection to an Object variable, ie: Set Obj =
mpMsgs.Item(i)
Any ideas as to how I can read these items would be greatly
appreciated.
'Main function to find the Root folder for the Mailbox and initiate
enumeration of folders
Function MapiSizeCheck()
Dim mpSess As MAPI.Session
Dim mpRoot As MAPI.Folder
Dim strStoreID As String
Set mpSess = New MAPI.Session
mpSess.Logon "Outlook"
'Get the Store ID for the main Exchange mailbox
strStoreID =
mpSess.GetDefaultFolder(CdoDefaultFolderInbox).StoreID
'Get the root folder (IPM_SUBTREE) for the Exchange Mailbox
Set mpRoot = mpSess.GetInfoStore(strStoreID).RootFolder
'Initiate enumeration of the folders
fnGetFolderSizes mpRoot
'Clean up
Set mpRoot = Nothing
mpSess.Logoff
Set mpSess = Nothing
End Function
'Recursive function to read enumerate each Folder MAPI.Messages
collection
Function fnGetFolderSizes(mpFdr As MAPI.Folder)
On Error Resume Next
Dim mpSub As MAPI.Folder
Dim mpMsgs As MAPI.Messages
Dim Obj As Object
'Get the collection of items in the folder
Set mpMsgs = mpFdr.Messages
lngCount = mpMsgs.Count
'Get the item details if items exist
If lngCount > 0 Then
'Enumerate the items in the collection to get each items
details (class, size etc)
For i = 1 To mpMsgs.Count
'ERROR OCCURS ON THIS NEXT LINE
Set Obj = mpMsgs.Item(i)
'ERROR! -2147024891 [Collaboration Data Objects -
[E_ACCESSDENIED(80070005)]]
'do stuff with item here...
Next
End If
'If the folder has sub-folders, call this procedure for the sub-
folder
If mpFdr.Fields(CdoPR_SUBFOLDERS) Then
For Each mpSub In mpFdr.Folders
fnGetFolderSizes mpSub
Next
End If
'Cleanup
Set Obj = Nothing
Set mpMsgs = Nothing
Set mpSub = Nothing
End Function
Regards
Greg Johncock