如何使用日期范围将电子邮件存档到 .pst 文件中?我想为每一年创建 .pst 文件。
我正在使用 MS Outlook 2003。
答案1
我知道的唯一方法是使用 MS Outlook 归档工具。您可以选择从/到(日期)进行归档,然后按名称命名您的 pst 文件。
您无法选择从 2009 年 1 月 1 日到 2010 年 1 月 1 日,但您可以存档从现在到 2011 年 1 月 1 日。然后,2010 年 12 月 31 日至 2010 年 1 月 1 日等等......
答案2
虽然这个问题相当老了,但我相信Robert McMurry 的宏观会起作用,因为这听起来正是原始问题所寻找的。
为了防止位衰减造成的最严重损失,下面是相关的代码块。实际文章对其功能和可能的增强功能(例如添加递归)有更详细的说明;这似乎只适用于单个文件夹(“收件箱”),可能可以用作起点。
Sub MoveOldEmails()
' Declare all variables.
Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objSourceFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim objVariant As Variant
Dim lngMovedMailItems As Long
Dim intCount As Integer
Dim intDateDiff As Integer
Dim strDestFolder As String
' Create an object for the Outlook application.
Set objOutlook = Application
' Retrieve an object for the MAPI namespace.
Set objNamespace = objOutlook.GetNamespace("MAPI")
' Retrieve a folder object for the source folder.
Set objSourceFolder = objNamespace.GetDefaultFolder(olFolderInbox)
' Loop through the items in the folder. NOTE: This has to
' be done backwards; if you process forwards you have to
' re-run the macro an inverese exponential number of times.
For intCount = objSourceFolder.Items.Count To 1 Step -1
' Retrieve an object from the folder.
Set objVariant = objSourceFolder.Items.Item(intCount)
' Allow the system to process. (Helps you to cancel the
' macro, or continue to use Outlook in the background.)
DoEvents
' Filter objects for emails or meeting requests.
If objVariant.Class = olMail Or objVariant.Class = olMeetingRequest Then
' This is optional, but it helps me to see in the
' debug window where the macro is currently at.
Debug.Print objVariant.SentOn
' Calculate the difference in years between
' this year and the year of the mail object.
intDateDiff = DateDiff("yyyy", objVariant.SentOn, Now)
' Only process the object if it isn't this year.
If intDateDiff > 0 Then
' Calculate the name of the personal folder.
strDestFolder = "Personal Folders (" & _
Year(objVariant.SentOn) & ")"
' Retrieve a folder object for the destination folder.
Set objDestFolder = objNamespace.Folders(strDestFolder).Folders("Inbox")
' Move the object to the destination folder.
objVariant.Move objDestFolder
' Just for curiousity, I like to see the number
' of items that were moved when the macro completes.
lngMovedMailItems = lngMovedMailItems + 1
' Destroy the destination folder object.
Set objDestFolder = Nothing
End If
End If
Next
' Display the number of items that were moved.
MsgBox "Moved " & lngMovedMailItems & " messages(s)."
End Sub