How to Quickly Back Up & Restore the Folder List of “Favorites” Section in Outlook

Have you ever been subject to the problem that all the folders in “Favorites” section are gone? To avoid this issue, you can use the ways introduced in this post to back up the folder list in “Favorites” section and quickly restore the folder list.

Some users have complained that when they start their Outlook, the folders in the “Favorites” section disappear strangely. At that point, they should locate each folder among all the folders and add them to “Favorites” section one by one. That is too tedious. It will be better if you can back up the folder list of “Favorites” in advance and restore it when you need it. Now, in the following, we will teach you to realize it via VBA code in quick time.

Back Up Folder List of “Favorites” Section to an Excel Sheet

  1. For a start, trigger Outlook VBA editor according to “How to Run VBA Code in Your Outlook“.
  2. Then, enable “MS Excel Object Library” with reference to “How to Add an Object Library Reference in VBA“.
  3. Next, put the following VBA code into a module.
Sub BackUpFolderListInFavorites()
    Dim objNavigationPane As Outlook.NavigationPane
    Dim objNavigationModule As Outlook.NavigationModule
    Dim objNavigationGroup As Outlook.NavigationGroup
    Dim objNavigationFolder As Outlook.NavigationFolder
    Dim objFolder As Outlook.folder
    Dim objExcelApp As Excel.Application
    Dim objExcelWorkbook As Excel.Workbook
    Dim objExcelWorksheet As Excel.Worksheet
    Dim nLastRow As Integer
 
    'Add a new Excel workbook
    Set objExcelApp = CreateObject("Excel.Application")
    Set objExcelWorkbook = objExcelApp.Workbooks.Add
    Set objExcelWorksheet = objExcelWorkbook.Sheets(1)
    objExcelApp.Visible = True
 
    With objExcelWorksheet
         .Cells(1, 1) = "Folder"
         .Cells(1, 1).Font.Bold = True
         .Cells(1, 2) = "Path"
         .Cells(1, 2).Font.Bold = True
    End With
 
    'Get the Favorites
    Set objNavigationPane = Application.ActiveExplorer.NavigationPane
    Set objNavigationModule = objNavigationPane.Modules.GetNavigationModule(olModuleMail)
    Set objNavigationGroup = objNavigationModule.NavigationGroups.GetDefaultNavigationGroup(olFavoriteFoldersGroup)
 
    On Error Resume Next
    For Each objNavigationFolder In objNavigationGroup.NavigationFolders
        Set objFolder = objNavigationFolder.folder
        nLastRow = objExcelWorksheet.Range("A" & objExcelWorksheet.Rows.Count).End(xlUp).Row + 1
        With objExcelWorksheet
             .Range("A" & nLastRow) = objFolder.Name
             .Range("B" & nLastRow) = objFolder.FolderPath
        End With
    Next
 
    objExcelWorksheet.Columns("A:B").AutoFit
End Sub

VBA Code - Back Up Folder List of Favorites Section to an Excel Sheet

  1. After that, press “F5” key button.
  2. At once, a new Excel worksheet will display, as shown in the following figure.Backed up Folder List in Excel
  3. Now, you can save the Excel file to a local folder at will.

Restore Folder List of “Favorites” Section from an Excel Sheet

  1. Still in Outlook VBA editor, copy the VBA code below into a module.
Sub RestoreFolderListFavorites()
    Dim objNavigationPane As Outlook.NavigationPane
    Dim objNavigationModule As Outlook.NavigationModule
    Dim objNavigationGroup As Outlook.NavigationGroup
    Dim strExcelFile As String
    Dim objExcelApp As Excel.Application
    Dim objExcelWorkbook As Excel.Workbook
    Dim objExcelWorksheet As Excel.Worksheet
    Dim objFolder As Outlook.folder
    Dim nRow, nLastRow As Integer
    Dim strFolderPath As String
 
    Set objNavigationPane = Application.ActiveExplorer.NavigationPane
    Set objNavigationModule = objNavigationPane.Modules.GetNavigationModule(olModuleMail)
    Set objNavigationGroup = objNavigationModule.NavigationGroups.GetDefaultNavigationGroup(olFavoriteFoldersGroup)
 
    'Change path to the Excel file containing the folder list in "Favorites" section
    strExcelFile = "E:\Folder List Favorites.xlsx"
 
    Set objExcelApp = CreateObject("Excel.Application")
    Set objExcelWorkbook = objExcelApp.Workbooks.Open(strExcelFile)
    Set objExcelWorksheet = objExcelWorkbook.Sheets("Sheet1")
    nLastRow = objExcelWorksheet.Range("A" & objExcelWorksheet.Rows.Count).End(xlUp).Row
   
    For nRow = 2 To nLastRow
        strFolderPath = objExcelWorksheet.Range("B" & nRow).Value
 
        Set objFolder = GetFolder(strFolderPath)
 
        If Not (objFolder Is Nothing) Then
           objNavigationGroup.NavigationFolders.Add objFolder
        End If
    Next nRow
End Sub

Function GetFolder(ByVal strPath As String) As Outlook.folder
    Dim objFolder As Outlook.folder
    Dim varFoldersArray As Variant
    Dim i As Integer
    Dim objSubFolders As Outlook.Folders

    If Left(strPath, 2) = "\\" Then
       strPath = Right(strPath, Len(strPath) - 2)
    End If
 
    varFoldersArray = Split(strPath, "\")
    Set objFolder = Application.Session.Folders.Item(varFoldersArray(0))
    If Not objFolder Is Nothing Then
       For i = 1 To UBound(varFoldersArray, 1)
           Set objSubFolders = objFolder.Folders
           Set objFolder = objSubFolders.Item(varFoldersArray(i))
           If objFolder Is Nothing Then
              Set GetFolder = Nothing
           End If
       Next
    End If
 
    Set GetFolder = objFolder
End Function

VBA Code - Restore Folder List of Favorites Section from an Excel Sheet

  1. Subsequently, move cursor to the first subroutine and press “F5” key.
  2. At once, all the folders recorded in the Excel worksheet will be added to the “Favorites” section, like the following screenshot.Restore Folders to Favorites

Cope with Miscellaneous Outlook Issues

For users who have utilized Outlook for decades, you may have ever suffered lots of troubles in Outlook, ranging from tiny errors to destructive Outlook corruption. It can be sure that no one is willing to accept that. Hence, users had better utilize get hold of a powerful external repair 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 repair SQL Server and outlook repair software products. For more information visit www.datanumen.com