Outlook VBA Code to Check Mail Size

This code, run on the currently open mail item, will display a message box giving you the size of the email in kilobytes.

Sub CheckMailSize()
Dim CurrentMsg As Outlook.MailItem
 On Error Resume Next
 Set CurrentMsg = ActiveInspector.CurrentItem
 On Error Goto 0

If (CurrentMsg Is Nothing) Or (TypeName(CurrentMsg)  "MailItem") Then
    MsgBox "Double-click on a message first."
    Exit Sub
End If

MsgBox "This message is " & CurrentMsg.Size & " kb."
Set CurrentMsg = Nothing

End Sub

And here is an application-level event handler that does the same thing (if you don't mind being interrupted every time you hit 'Send'):

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
If TypeName(Item) = "MailItem" Then
    Dim Msg As Outlook.MailItem
    Set Msg = Item

    MsgBox "This message is " & Msg.Size & " kb."

    Set Msg = Nothing
End If

Enjoy,
JP

Related Articles:

About JP

I'm just an average guy who writes VBA code for a living. This is my personal blog. Excel and Outlook are my thing, with a sprinkle of Access and Word here and there. Follow this space to learn more about VBA. Keep Reading »

Share This Article:

Share and bookmark this articledelicious buttonfacebook buttonlinkedin buttonstumbleupon buttontwitter button
Comments on this article are closed. Why?

Site last updated: February 9, 2012