Last reviewed on April 27, 2015   —  3 Comments

"Is there any way I can set up a warning (or possibly limit) on the size of file I can email? I'm guilty of accidentally sending 13mb files."

Sure, you can use VBA to warn you.

A very basic warning uses this simple code:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
     If Item.Attachments.Count > 0 Then
         ans = MsgBox("Is the attachment too big?", vbYesNo)
       If ans = vbYes Then Cancel = True
     End If
End Sub

This simple procedure checks for the presence of attachments and asks if the attachments are too large. While this is fine if you don't send a lot of attachments, it would be even better if you were alerted only when the message size was too large.

Better VBA

Outlook MVP Michael Bauer offers this procedure that checks for the presence of attachments and if any are found, it checks the message size. When the message exceeds the Max_item_size you configured, a warning dialog pops up.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
   If TypeOf Item Is Outlook.MailItem Then
      Cancel = Not (ConfirmBigAttachments(Item))
   End If
End Sub
Private Function ConfirmBigAttachments(oMail As Outlook.MailItem) As Boolean
' by Michael Bauer 
Dim lSize As Long
Const MAX_ITEM_SIZE As Long = 1048576 ' in Bytes. This is 1 MB
Dim bSend As Boolean
bSend = True
    If oMail.Attachments.Count Then
       lSize = oMail.Size
      If lSize > MAX_ITEM_SIZE Then
bSend = (MsgBox("Item's size: " & lSize & " Byte. Cancel?", vbYesNo) = vbNo)
      End If
    End If
  ConfirmBigAttachments = bSend
End Function

How to Use

To use either of these code samples with Outlook, open the VBA editor (Alt+F11) then copy and paste the code into ThisOutlookSession. The max_item_size is set for 1 megabyte but can be changed to any number. Save it and every time you send a message, the ItemSend procedure will run.

If you need help converting megabytes to bytes, go to google and type "x megabyte in bytes" into the search field, where x is the number you need to convert.

Discuss in our community


Leave a Reply

Please post long or more complicated questions at OutlookForums by

If the Post Comment button disappears, press your Tab key.