Private Sub Form_Load()
Dim strMailBoxName As String
strMailBoxName = "MyAlias"
Debug.Print "Mailbox Size: " & dblGetMailboxSize(strMailBoxName)
End Sub
Private Function dblGetMailboxSize(strMailBoxName As String) As Double
'Requires reference to:
'Active DS Type Library (activeds.tlb)
'Microsoft ActiveX Data Objects 2.5 Library (msado15.dll)
Dim Info As New ADSystemInfo
Dim sDomainName As String
Dim sUserName As String
Dim mailboxSZ As Double
Dim sURL As String
Dim sSQL As String
Dim Rs As New ADODB.Recordset
Dim Rec As New ADODB.Record
mailboxSZ = 0
sDomainName = Info.DomainDNSName
sUserName = strMailBoxName
sURL = "file://./backofficestorage/" & sDomainName & _
"/MBX/" & sUserName
Rec.Open sURL
sSQL = "Select"
sSQL = sSQL & " ""http://schemas.microsoft.com" & _
"/exchange/foldersize"" "
sSQL = sSQL & ", ""DAV:displayname"" "
sSQL = sSQL & " from scope ('shallow traversal of " & Chr(34)
sSQL = sSQL & sURL & Chr(34) & "')"
sSQL = sSQL & "Where ""DAV:isfolder""=true"
Rs.Open sSQL, Rec.ActiveConnection
If Not Rs.EOF Then
Rs.MoveFirst
End If
While Not Rs.EOF
'Uncomment the following lines if you would like to<BR/>
'see the size of each folder
'Debug.Print Rs.Fields("DAV:displayname").Value
'Debug.Print Rs.Fields("http://schemas.microsoft.com" & _
' "/exchange/foldersize").Value
mailboxSZ = mailboxSZ + _
Rs.Fields("http://schemas.microsoft.com" & _
"/exchange/foldersize").Value
Rs.MoveNext
Wend
dblGetMailboxSize = mailboxSZ
Rs.Close
Rec.Close
End Function