I am retired and have not had access to a shared mailbox for eight years. My recollection is that the VBA that worked on private stores also worked on shared ones. So the code below should work for you but I have not tested it on a shared mailbox.
I have been experimenting with the first part of your problem: determining the size of a store using VBA. My results have been inconsistent.
I have two stores (Archive Folders and Backup) that I do not remember creating so I assume they came with the installation.
Archive Folders has four visible folders (Junk Email, Drafts, Deleted Items and Sent Items) and three invisible folders (Tasks, Journal and Calendar) and one pseudo-folder (Search Folders). This store has never been used and all folders are empty.
Backup has four visible folders (Junk Email, Drafts, Deleted Items and InBox), the same invisible folders and the same pseudo-folder. There are two emails in Inbox as the result of me using this store to test a macro.
By “visible” I mean they appear in the Outlook Folder pane and are accessible with VBA. By “invisible” I mean they do not appear in the Outlook Folder pane but are accessible with VBA. By “pseudo” I mean they appear in the Outlook Folder pane but are not accessible with VBA.
Summing the size of the items within these stores gives a total item size for Archive Folders of 0 bytes and a total item size for Backup of 66,207 bytes. Accessing these files with File Explorer and looking at Properties, gives a total file size for either of 265 KB or 271,360 bytes with the size on disk being a little bigger.
Last night, the total size of the items within my principal store (which is one of my mail account stores) was 507,896,393 bytes. The File Explorer file size was 733,938,688 bytes which reduced to 609,756,160 bytes after compaction. This morning, after receiving a few more emails, the total item size has increased to 508,834,935 bytes but the file size is unchanged. Outlook’s Mailbox Setting’s gives the size of this folder as 496,845 KB. Note: 496,845 * 1,024 = 508,769,280 bytes which is less than the total item size although there is nothing in that store except mail items.
The code below calculates the total item size of every store it can access. Perhaps you can see a pattern I have missed. Or, knowing when the system complains about the mailbox size, you can deduce the total item size at which you need to take action.
Option Explicit
Sub CalcSizeOfAllStores()
' Displays name of each store and the size of its contents
Dim FldrCrnt As Folder
Dim InxFldrChild As Long
Dim InxStoreCrnt As Long
Dim StoreCrnt As Folder
Dim StoreSize As Long
Dim TotalSize As Long
TotalSize = 0&
With Application.Session
For InxStoreCrnt = 1 To .Folders.Count
Set StoreCrnt = .Folders(InxStoreCrnt)
With StoreCrnt
StoreSize = 0&
For InxFldrChild = .Folders.Count To 1 Step -1
Set FldrCrnt = .Folders(InxFldrChild)
StoreSize = StoreSize + GetSizeOfFolder(FldrCrnt)
Next
Debug.Print PadL(Format(StoreSize, "#,##0"), 15) & " " & .Name
TotalSize = TotalSize + StoreSize
End With
Next
End With
Debug.Print String(15, "-")
Debug.Print PadL(Format(TotalSize, "#,##0"), 15)
End Sub
Function GetSizeOfFolder(FldrCrnt) As Long
' Return the size of every item within FldrCrnt and its children
Dim InxFldrChild As Long
Dim InxItem As Long
Dim FolderSize As Long
FolderSize = 0&
With FldrCrnt
' Get Total size of items within folder
For InxItem = .Items.Count To 1 Step -1
FolderSize = FolderSize + .Items(InxItem).Size
Next
' Add size of each child folder
For InxFldrChild = .Folders.Count To 1 Step -1
FolderSize = FolderSize + GetSizeOfFolder(.Folders(InxFldrChild))
Next
'Debug.Print " " & PadL(Format(FolderSize, "#,##0"), 15) & " " & .Name
End With
GetSizeOfFolder = FolderSize
End Function