Outlook VBA Code to Check Mail Size


January 22, 2008 – 8:55 pm by JP

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


If you enjoyed this page, share it!
    StumbleUpon Technorati Digg Google del.icio.us MisterWong TwitThis

Print This Post Print This Post  |  Email This Post Email This Post  |  rss Subscribe to Posts Feed  |  rss Subscribe to Comments

Filed Under: Outlook, VBA
Tags: , ,

Post a Comment


Certain comments (including first-time comments) are subject to moderation and will not appear immediately. You can use HTML tags in your comment. If you include a greater-than or less-than sign or anything else that could be interpreted as HTML, you need to escape those characters. To post VBA code in your comment, use [VBA] tags, like this: [VBA]Code goes here[/VBA].





Subscribe without commenting

Keep Reading:

Browse Posts:


« MS KB Articles added to VBA Search Engine || Formula for Date/Time Subtraction in Excel »