How to Quickly Export an Outlook Folder with All Subfolders & Items to a Windows Folder

At times, you may want to batch export an Outlook folder with all subfolders and items to a Windows folder. This article will teach you such a method that is applying Outlook VBA.

When you would like to export an Outlook folder to local drive with all items in the same folder structure, if you select to save and export manually, it’ll take you a lot of time. Thus, why don’t you resort to other means, such as any export tools or VBA codes? Here we will unveil such a piece of VBA code to you. It will permit you to achieve it like a breeze.

Quickly Export All Subfolders & Items in an Outlook Folder to a Windows Folder

Export All Subfolders & Items in an Outlook Folder to a Windows Folder

  1. At the very outset, start your Outlook program.
  2. Then in the main Outlook window, press the “Alt + F11” key shortcuts.
  3. Subsequently, the “Microsoft Visual Basic for Applications” window will pop up.
  4. Next you need to open a blank module and copy the following VBA codes into it.
Private objFileSystem As Object
 
Private Sub ExportFolderWithAllItems()
    Dim objFolder As Outlook.Folder
    Dim strPath As String
 
    'Specify the root local folder
    'Change it as per your needs
    strPath = "E:\Outlook\"
 
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
 
    'Select a Outlook PST file or Outlook folder
    Set objFolder = Outlook.Application.Session.PickFolder
 
    Call ProcessFolders(objFolder, strPath)
 
    MsgBox "Complete", vbExclamation
End Sub
 
Private Sub ProcessFolders(objCurrentFolder As Outlook.Folder, strCurrentPath As String)
    Dim objItem As Object
    Dim strSubject, strFileName, strFilePath As String
    Dim objSubfolder As Outlook.Folder
 
    'Create the local folder based on the Outlook folder
    strCurrentPath = strCurrentPath & objCurrentFolder.Name
    objFileSystem.CreateFolder strCurrentPath
 
    For Each objItem In objCurrentFolder.Items
 
        strSubject = objItem.Subject
 
        'Remove unsupported characters in the subject
        strSubject = Replace(strSubject, "/", " ")
        strSubject = Replace(strSubject, "\", " ")
        strSubject = Replace(strSubject, ":", "")
        strSubject = Replace(strSubject, "?", " ")
        strSubject = Replace(strSubject, Chr(34), " ")

        strFileName = strSubject & ".msg"
 
        i = 0
        Do Until False
           strFilePath = strCurrentPath & "\" & strFileName
           'Check if there exist a file in the same name
           If objFileSystem.FileExists(strFilePath) Then
              'Add a sequence order to the file name
              i = i + 1
              strFileName = strSubject & " (" & i & ").msg"
           Else
              Exit Do
          End If
        Loop
 
        'Save as MSG file
        objItem.SaveAs strFilePath, olMSG
    Next
 
    'Process subfolders recursively
    If objCurrentFolder.folders.Count > 0 Then
       For Each objSubfolder In objCurrentFolder.folders
           Call ProcessFolders(objSubfolder, strCurrentPath & "\")
       Next
    End If
End Sub

VBA Code - Export All Subfolders & Items in an Outlook Folder to a Windows Folder

  1. After that, you need to ensure that your Outlook permits macros in the macro settings.
  2. Eventually, you can have a try.
  • Firstly, back to the new macro window.
  • Next click into “ExportFolderWithAllItems” subroutine.
  • Then press F5 key button to run this macro.
  • After that, you need to select a specific folder.Select a specific Outlook folder
  • Lastly, when you get a message saying “Complete”, you can access the predefined local folder. You’ll find all items have been saved in the same folder structure.Effects: Windows Folder

Prevent Data Loss from Outlook Crashes

Perhaps you have ever encountered many Outlook crashes. Most of time, after a restart, Outlook will be able to work as normal. However, there is also a case that our PST file may get corrupted. At that time, you will try best to retrieve your PST data, such as recurring to an experienced tool like DataNumen Outlook Repair. It is able to fix Outlook errors and extract data from compromised PST file without breaking a sweat.

Author Introduction:

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

Comments are closed.