如何通過 VBA 將 Outlook PST 文件中的所有電子郵件批量移動到特定文件夾

立即分享:

如果您想將一個 PST 文件中的所有電子郵件移動到另一個 PST 文件中的特定文件夾,您可以使用本文介紹的方法。 它將教您如何使用VBA快速獲取。

有時,出於某些原因,您可能需要將特定 PST 文件中的所有電子郵件移動到另一個 PST 文件中的特定文件夾。 在這種情況下,如果您手動進行操作,無疑會非常麻煩。 因此,在這裡我們將教一種快速方法,該方法將使用 VBA 循環遍歷某個 PST 文件中的所有文件夾,並將每封電子郵件移動到特定文件夾。 繼續閱讀以實現詳細的步驟和代碼。

將 Outlook PST 文件中的所有電子郵件批量移動到特定文件夾

將 Outlook PST 文件中的所有電子郵件批量移動到特定文件夾

  1. 首先,啟動Outlook應用程序。
  2. 然後您可以切換到“Developer”選項卡並單擊“Visual Basic”按鈕。 或按“Alt + F11”快捷鍵。
  3. 隨後,在彈出的 VBA 編輯器窗口中,打開一個未使用的模塊或直接插入一個新模塊。
  4. 接下來將以下 VBA 代碼複製並粘貼到此模塊中。
Private Sub GetAllFolders()
    Dim objFolders As Outlook.Folders
    Dim objFolder As Outlook.Folder
 
    'Get all the folders in a specific PST file
    Set objFolders = Outlook.Application.Session.Folders("Personal").Folders
 
    For Each objFolder In objFolders
        Call MoveEmails(objFolder)
    Next
End Sub
 
Private Sub MoveEmails(ByVal objFolder As Outlook.Folder)
    Dim objTargetFolder As Outlook.Folder
    Dim objSubFolder As Outlook.Folder
    Dim i As Long
    Dim objMail As Outlook.MailItem
 
    'Get the specific destination folder
    'You can change it as per your case
    Set objTargetFolder = Outlook.Application.Session.Folders("John Smith").Folders("New")
 
    If objTargetFolder Is Nothing Then
       Set objTargetFolder = Outlook.Application.Session.Folders("John Smith").Folders.Add("New")
    End If
 
    'Move each emails in the folder to the destination folder
    For i = objFolder.Items.Count To 1 Step -1
        If objFolder.Items.Item(i).Class = olMail Then
           Set objMail = objFolder.Items.Item(i)
           objMail.Move objTargetFolder
        End If
    Next i
 
    'Process the subfolders in the folder recursively
    If (objFolder.Folders.Count > 0) Then
       For Each objSubFolder In objFolder.Folders
           Call MoveEmails(objSubFolder)
       Next
    End If
End Sub

VBA 代碼 - 將 Outlook PST 文件中的所有電子郵件批量移動到特定文件夾

  1. 之後,將您的Outlook宏安全級別更改為低。
  2. 最後,您可以通過單擊工具欄中的“運行”圖標或按“F5”鍵來運行新宏。
  3. 一次,特定文件夾中所有文件夾的所有電子郵件將被批量移動到預定文件夾中。

及時搶救您的 PST 數據

如果不幸受苦 PST損壞,那你會怎麼做? 通常,您的第一個想法必須盡快取回受損的 PST 數據。 像往常一樣,最簡單的方法是從最新的數據備份中恢復。 但是,如果數據備份是幾週前的,它可能沒有用。 在這種情況下,您別無選擇,只能使用強大的恢復工具,例如 DataNumen Outlook Repair.

作者簡介:

Shirley Zhang是的數據恢復專家 DataNumen,Inc.是數據恢復技術的全球領導者,包括 mdf修復 和Outlook修復軟件產品。 欲了解更多信息,請訪問 萬維網。datanumen.COM

立即分享:

評論被關閉。