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.

VBA:
  1. Sub CheckMailSize()
  2. Dim CurrentMsg As Outlook.MailItem
  3.  On Error Resume Next
  4.  Set CurrentMsg = ActiveInspector.CurrentItem
  5.  On Error Goto 0
  6.  
  7. If (CurrentMsg Is Nothing) Or (TypeName(CurrentMsg)  "MailItem") Then
  8.     MsgBox "Double-click on a message first."
  9.     Exit Sub
  10. End If
  11.  
  12. MsgBox "This message is " & CurrentMsg.Size & " kb."
  13. Set CurrentMsg = Nothing
  14.  
  15. 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'):

VBA:
  1. Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  2. If TypeName(Item) = "MailItem" Then
  3.     Dim Msg As Outlook.MailItem
  4.     Set Msg = Item
  5.  
  6.     MsgBox "This message is " & Msg.Size & " kb."
  7.  
  8.     Set Msg = Nothing
  9. End If

Enjoy,
JP



Print This Post Print This Post  |  Email This Post Email This Post  |  Permalink  |  Subscribe to this feed Subscribe now!

Filed Under: Outlook, VBA
Tags: , ,

This post has 8 views since January 22, 2008 – 8:55 pm.

Post a Comment

To post VBA code in your comment, use [VBA] tags, like this: [VBA]Code goes here[/VBA].


Browse Posts:


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