我有一個用於存檔共享郵箱中的T-1電子郵件的宏。在共享郵箱中存檔郵件阻止他人使用Outlook
問題是,如果我運行宏,我的所有同事都將凍結Outlook或不會發送他們的電子郵件,直到我的宏不停止。
歡迎任何幫助。
Sub Archive_Outlook_eMails()
Dim SourceFolder As Outlook.MAPIFolder, DestFolder As Outlook.MAPIFolder
Dim MailItem As Object
Dim SourceMailBoxName As String, DestMailBoxName As String
Dim Source_Pst_Folder_Name As String, Dest_Pst_Folder_Name As String
Dim MailsCount As Double, NumberOfDays As Double
Dim nam As String
Dim dateYear As String
Dim dateStr As String
NumberOfDays = 0
Source_Pst_Folder_Name = "Inbox"
Set SourceFolder = Session.Folders("Mailbox - Office").Folders("Inbox").Folders("Copy")
MailsCount = SourceFolder.Items.Count
While MailsCount > 0
Set MailItem = SourceFolder.Items.Item(MailsCount)
On Error GoTo FFF
If VBA.DateValue(VBA.Now) - VBA.DateValue(MailItem.ReceivedTime) > NumberOfDays Then
dateStr = GetDate(MailItem.SentOn)
dateStr = Format(dateStr, "mmmm")
dateYear = GetDate(MailItem.SentOn)
dateYear = Format(dateYear, "yyyy")
nam = "Archive Office" & dateStr & " " & dateYear
Set DestFolder = Outlook.Session.Folders(nam).Folders("Inbox").Folders("Copy")
Dim myCopiedItem As Object
Set myCopiedItem = MailItem.Copy
myCopiedItem.Move DestFolder
End If
FFF:
Dim oTemp As Object
If TypeName(oTemp) = "Outlook.ReportItem" Then
Set oMessage = oTemp
oMessage.Copy DestFolder
End If
Resume Next
MailsCount = MailsCount - 1
Wend
Call send_email_for_finish
End Sub
在'當MailsCount> 0後添加'DoEvents'' – 0m3r
爲什麼你檢查'NumberOfDays = 0'如果你存檔的一切?跳過這個來加速你的代碼。 – 0m3r
我正在歸檔所有的t-2電子郵件 – wittman