Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming VBA / October 2007

Tip: Looking for answers? Try searching our database.

get outlook mailbox size from vba

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bobm - 11 Aug 2007 13:44 GMT
Hello,

I am looking for some VBA code to get the Outlook Mailbox size on the
exchange server from Access.

I found this url http://support.microsoft.com/kb/320071 but not support by
VBA.

I am sending email from Access using the Outlook SendObject and before
sending I want to check the Mailbox size to ensure the Mailbox size is under
the size quota.

Appreciate any help.

bobm
bobm - 11 Aug 2007 14:08 GMT
Sub GetFolderSize()
Dim lFolderSize As Long
Dim objSubFolder As MAPIFolder

 Set objApp = CreateObject("Outlook.Application")
 Set objNS = objApp.GetNamespace("MAPI")
 Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
 Set objOutlookToday = objInbox.Parent
 
 For Each objSubFolder In objOutlookToday.Folders
   lFolderSize = lFolderSize + GetSubFolderSize(objSubFolder)
 Next
 MsgBox "Total Size = " & lFolderSize
End Sub

Function GetSubFolderSize(objFolder As MAPIFolder) As Long
Dim lFolderSize As Long
Dim objSubFolder As MAPIFolder

 For Each objItem In objFolder.Items
   lFolderSize = lFolderSize + objItem.Size
 Next
   
 ' process all the subfolders of this folder
 For Each objSubFolder In objFolder.Folders
   'Do something with objFolder
   lFolderSize = lFolderSize + GetSubFolderSize(objSubFolder)
 Next
   
 GetSubFolderSize = lFolderSize
 Set objFolder = Nothing
 Set objItem = Nothing
End Function
bobm - 11 Aug 2007 14:08 GMT
Sub GetFolderSize()
Dim lFolderSize As Long
Dim objSubFolder As MAPIFolder

 Set objApp = CreateObject("Outlook.Application")
 Set objNS = objApp.GetNamespace("MAPI")
 Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
 Set objOutlookToday = objInbox.Parent
 
 For Each objSubFolder In objOutlookToday.Folders
   lFolderSize = lFolderSize + GetSubFolderSize(objSubFolder)
 Next
 MsgBox "Total Size = " & lFolderSize
End Sub

Function GetSubFolderSize(objFolder As MAPIFolder) As Long
Dim lFolderSize As Long
Dim objSubFolder As MAPIFolder

 For Each objItem In objFolder.Items
   lFolderSize = lFolderSize + objItem.Size
 Next
   
 ' process all the subfolders of this folder
 For Each objSubFolder In objFolder.Folders
   'Do something with objFolder
   lFolderSize = lFolderSize + GetSubFolderSize(objSubFolder)
 Next
   
 GetSubFolderSize = lFolderSize
 Set objFolder = Nothing
 Set objItem = Nothing
End Function
85ascMcLaren - 10 Oct 2007 14:57 GMT
Good info.  I was hoping that there was a direct property to pull the mailbox
size from instead of traversing all the folders and items under the mailbox
object, but I guess not.  I am not allowed to install any third party add-ins
on the client PCs, so I guess this is the only way?

  In using this, I have found a problem.  Encrypted emails.  The size
property will not pull when it encounters an encrypted email.  I error out
with a -2147217660 - Method 'Size' of object 'MailItem' failed.

  Any suggestions on either of these questions?  Is there a more direct way
of pulling a size from the mailbox or even the individual folders (inbox,
sent, etc) without traversing through each item and without installing any
other add-ins?  If not - any way around the encrypted problem.... ??

  Thanks,
     Jason

> Sub GetFolderSize()
> Dim lFolderSize As Long
[quoted text clipped - 29 lines]
>   Set objItem = Nothing
> End Function
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.