How to Auto Move Large Sent Emails from Your Outlook to Local Drive

So as to keep mailbox in small size, you can save the large Outlook emails to local drive and delete them from Outlook. This article will take large sent emails as an example and guide you to use VBA to achieve it.

As we all know, if a PST file is too large, it will become more vulnerable. That is to say, the PST file will be prone to error and corruption. Thus, in order to avoid PST data corruption or loss, you need keep your PST file in small size. One of the most effective ways is to save the large items to local drive and then remove them from Outlook. For instance, you can move large sent email from Outlook to local drive. Here we’ll teach you to use VBA to get it. Now read on to learn the detailed steps and VBA codes.

Auto Move Large Sent Emails from Your Outlook to Local Drive

Auto Move Large Sent Emails from Your Outlook to Local Drive

  1. At the very outset, launch your Outlook program.
  2. Then switch to “Developer” tab and hit the “Visual Basic” button.
  3. Next you will get into the Outlook VBA editor window successfully.
  4. Subsequently, open the “ThisOutlookSession” project.
  5. After that, copy the following VBA codes into the “ThisOutlookSession”.
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim objMail As Outlook.MailItem
    Dim lMailSize As Long
    Dim strName As String
    Dim strPath
 
    If Item.Class = olMail Then
       Set objMail = Item
 
       'Count the size by megabyte
       lMailSize = objMail.Size
       lMailSize = (lMailSize / 1024) / 1024
 
       'If the current sent email exceeds 2 MB
       'You can change the number as per your needs
       If lMailSize >= 2 Then
 
          strName = objMail.Subject
          'Remove the unsupported characters in the subject
          strName = Replace(strName, "/", " ")
          strName = Replace(strName, "\", " ")
          strName = Replace(strName, ":", " ")
          strName = Replace(strName, "?", " ")
          strName = Replace(strName, Chr(34), " ")
          strName = Replace(strName, "|", " ")
          strName = Replace(strName, "<", " ")
          strName = Replace(strName, ">", " ")
 
          strName = Format(objMail.SentOn, "yyyy-mm-dd") & " " & strName & ".msg"
 
          'You can change the saving path as per your needs
          strPath = "E:\Large Sent Items\"
          objMail.SaveAs strPath & strName, olMSG
 
          'Delete this email
          objMail.DeleteAfterSubmit = True
        End If
    End If
End Sub

VBA Code - Auto Move Large Sent Emails from Your Outlook to Local Drive

  1. Later sign this code as usual.
  2. And then change Outlook macro settings to permit the signed macros.
  3. From now on, this subroutine will be triggered when you click “Send” button to send an email. If the email exceeds the predefined size limit, Outlook will auto save it to the predetermined local folder and delete it from mailbox.

Withstand Annoying Outlook Errors

It is inevitable that your PST file will become larger and larger. In that case, you’ll be confronted with various potential threats. In general, faced with small issues in Outlook, you can use the inbox repair tool – Scanpst to have a try. If it fails, you can then resort to a more robust tool, such as DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including corrupted sql and outlook repair software products. For more information visit www.datanumen.com

Leave a Reply

Your email address will not be published. Required fields are marked *