Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in


How to copy Outlook folder structure to desktop (windows explorer)?

As you know, we can apply the Archive feature to copy folder structure to another Outlook, but do you know how to copy Outlook folder structure to a certain window folder, such as desktop? This article will introduce a VBA to copy Outlook folder structure to windows explorer easily.

Copy Outlook folder structure to desktop (windows explorer)

Kutools for Outlook: 100+ New Advanced Tools for Outlook.
Office Tab: Enable Tabbed Editing and Browsing in Office, Just Like Chrome, Firefox, IE 8/9/10.
Classic Menu: Bring Old Menus and Toolbars Back to Office 2007, 2010, 2013, 2016 and 2019.

Copy Outlook folder structure to desktop (windows explorer)

Please follow below steps to copy Outlook folder structure to the desktop or windows explorer.

1. On the Navigation Pane, please click to highlight the specified folder whose folder structure you will copy, and press Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. Click Tools > References to open the References dialog box. Then in the dialog box check the Microsoft Scripting Runtime option, and click the OK button. See screenshot:

3. Click Insert > Module, and copy and paste below VBA code into the new module window.

VBA: Copy Outlook folder structure to windows explorer

Dim xFSO As Scripting.FileSystemObject
Sub CopyOutlookFldStructureToWinExplorer()
    ExportAction "Copy"
End Sub
Sub ExportAction(xAction As String)
Dim xFolder As Outlook.Folder
Dim xFldPath As String
xFldPath = SelectAFolder()
If xFldPath = "" Then
    MsgBox "You did not select a folder. Export cancelled.", vbInformation + vbOKOnly, "Kutools for Outlook"
    Set xFSO = New Scripting.FileSystemObject
    Set xFolder = Outlook.Application.ActiveExplorer.CurrentFolder
    ExportOutlookFolder xFolder, xFldPath
End If
Set xFolder = Nothing
Set xFSO = Nothing
End Sub

Sub ExportOutlookFolder(ByVal OutlookFolder As Outlook.Folder, xFldPath As String)
Dim xSubFld As Outlook.Folder
Dim xItem As Object
Dim xPath As String
Dim xFilePath As String
Dim xSubject As String
Dim xCount As Integer
Dim xFilename As String
On Error Resume Next
xPath = xFldPath & "\" & OutlookFolder.Name
If Dir(xPath, 16) = Empty Then MkDir xPath
For Each xItem In OutlookFolder.Items
    xSubject = ReplaceInvalidCharacters(xItem.Subject)
    xFilename = xSubject & ".msg"
    xCount = 0
    xFilePath = xPath & "\" & xFilename
    If xFSO.FileExists(xFilePath) Then
        xCount = xCount + 1
        xFilename = xSubject & " (" & xCount & ").msg"
        xFilePath = xPath & "\" & xFilename
    End If
    xItem.SaveAs xFilePath, olMSG
For Each xSubFld In OutlookFolder.Folders
    ExportOutlookFolder xSubFld, xPath
Set OutlookFolder = Nothing
Set xItem = Nothing
End Sub

Function SelectAFolder() As String
Dim xSelFolder As Object
Dim xShell As Object
On Error Resume Next
Set xShell = CreateObject("Shell.Application")
Set xSelFolder = xShell.BrowseForFolder(0, "Select a folder", 0, 0)
If Not TypeName(xSelFolder) = "Nothing" Then
    SelectAFolder = xSelFolder.self.Path
End If
Set xSelFolder = Nothing
Set xShell = Nothing
End Function
Function ReplaceInvalidCharacters(Str As String) As String
Dim xRegEx
Set xRegEx = CreateObject("vbscript.regexp")
xRegEx.Global = True
xRegEx.IgnoreCase = False
xRegEx.Pattern = "\||\/|\<|\>|""|:|\*|\\|\?"
ReplaceInvalidCharacters = xRegEx.Replace(Str, "")
End Function

4. Press F5 key or click the Run button to run this VBA.

5. In the popping out Browse For Folder dialog box, please select the specified folder you will place the copied folder structure, and click the OK button. See screenshot:

Now go to the specified folder, you will see the folder structure is copied to the specified hard disc. See screenshot:

Note: the folder items, such as emails, appointments, tasks, etc. are also copied into corresponding folders in the hard disc.

Related Articles


Recommended Productivity Tools

shot kutools outlook kutools tab 1180x121
shot kutools outlook kutools plus tab 1180x121

Kutools for Outlook - More than 100 Advanced Functions for Outlook, Improve 70% Efficiency For you

  • Complicated and repeated operations can be done a one-time processing in seconds.
  • Forward multiple emails individually with one-click, and auto forward by rules.
  • Auto CC/BCC every sending email and easy for customizing rules, and auto reply without requiring exchange server.
  • Powerful junk emails filter, remove duplicate emails, reply with attachment, bunch of one-click operations, and so on...
  • 60-day unlimited free trial. 60-day money back guarantee. 2 years free upgrade and support. Buy once, use forever.
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Ammar · 1 months ago
    Hello I have one question, I used the above mentioned code, but it is missing the related conversations as it has the same subject. This is created problem as the numbers of items in outlook not matching with number of items in folder. Can you please help to edit the above code so that it also paste all the items even though it has same subject ?
  • To post as a guest, your comment is unpublished.
    Kristian · 5 months ago
    It works (sort of), but (a) there were more messages exported to one folder than were in the corresponding Outlook Folder and (b) there were fewer messages exported to one folder than were in the Outlook Folder and (c) (not 100% sure) I think one message went to the wrong folder.
  • To post as a guest, your comment is unpublished.
    Amy · 6 months ago
    I have Outlook 15, and the macro won't replace the "/" where used in Outlook folder names. It just skips those folders. Is this a compatibility issue?
  • To post as a guest, your comment is unpublished.
    Expert Scrapping - Intégration - Analyse · 9 months ago

    Serait-il possible de stocker les mails dans un fichier .pst ?

    D'avance merci pour vos retours.


    Ando Rakotomalala