跳至主要内容

如何将Outlook文件夹结构复制到桌面(Windows资源管理器)?

Author: Kelly Last Modified: 2025-05-07

众所周知,我们可以使用归档功能将文件夹结构复制到另一个Outlook中,但您是否知道如何将Outlook文件夹结构复制到某个特定的窗口文件夹,例如桌面?本文将介绍一种VBA方法,轻松将Outlook文件夹结构复制到Windows资源管理器。

将Outlook文件夹结构复制到桌面(Windows资源管理器)


将Outlook文件夹结构复制到桌面(Windows资源管理器)

请按照以下步骤将Outlook文件夹结构复制到桌面或Windows资源管理器。

1. 在导航窗格中,请点击以突出显示要复制其文件夹结构的指定文件夹,然后按“Alt”+“F11”键打开Microsoft Visual Basic for Applications窗口。

the screenshot of step about copying Outlook folder structure to desktop (windows explorer) using vba 1

2. 点击“工具”>“引用”以打开“引用”对话框。然后在对话框中勾选“Microsoft Scripting Runtime”选项,并点击“确定”按钮。参见截图:

the screenshot of step about copying Outlook folder structure to desktop (windows explorer) using vba 2

3. 点击“插入”>“模块”,并将以下VBA代码复制并粘贴到新模块窗口中。

VBA:将Outlook文件夹结构复制到Windows资源管理器

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"
Else
    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
Next
For Each xSubFld In OutlookFolder.Folders
    ExportOutlookFolder xSubFld, xPath
Next
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. 按“F5”键或点击“运行”按钮来运行此VBA。

5. 在弹出的“浏览文件夹”对话框中,请选择要放置复制的文件夹结构的指定文件夹,并点击“确定”按钮。参见截图:

the screenshot of step about copying Outlook folder structure to desktop (windows explorer) using vba 3

现在转到指定的文件夹,您将看到文件夹结构已复制到指定的硬盘中。参见截图:

the screenshot of step about copying Outlook folder structure to desktop (windows explorer) using vba 4

注意:文件夹中的项目,例如邮件、约会、任务等,也会被复制到硬盘中的相应文件夹中。


相关文章

如何在Outlook中将文件夹结构复制到新的PST数据文件中?