'What is the VBA property for: Server folder contains x items?
I like to compare the amount of items in each folder on the Exchange server with the amount of items in my local Outlook file.
In Outlook I can use the following to get the item count per folder
Dim Folder As Outlook.MAPIFolder
Set Folder = objNS.Folders("xxx").Folders("Inbox")
Debug.Print Folder.Items.Count
How do I get the item count on the server like in the following screenshot?
Solution 1:[1]
To find out the number of items in a server (online) folder, you will need to open that folder in the online mode.
In Extended MAPI (C++ or Delphi) you would need to use the MAPI_NO_CACHE
bit when calling IMAPISession::OpenEntry
- you can play with that bit in OutlookSpy (I am its author): click IMAPIFolder button, select PR_ENTRYID property, right click, select IMAPISession::OpenEntry, make sure MAPI_NO_CACHE is checked. One you do that, you can retrieve the count either from the IMAPITable
contents table or by reading the PR_CONTENT_COUNT
(0x36020003) MAPI property from the folder itself.
Outlook Object Model will not let you override the caching mode on the per folder/message level - the whole profile must have the right connection mode.
In case of languages other than C++ or Delphi, you can use Redemption (I am also its author) - its versions of GetFolderFromID
, GetMessageFromID
, etc. allow to pass flags to be used by IMAPISession::OpenEntry
.
MAPI_NO_CACHE = &H0200
MAPI_BEST_ACCESS = &H0010
set OomFolder = Application.ActiveExplorer.CurrentFolder
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set RdoFolder = Session.GetFolderFromID(OomFolder.EntryID, , MAPI_NO_CACHE Or MAPI_BEST_ACCESS)
MsgBox "Number of items in the online folder: " & RdoFolder.Items.Count
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |