【发布时间】:2017-04-29 01:17:48
【问题描述】:
我在 Outlook 中的邮件包含所有特定主题。我有一个包含主题和文件夹名称的 Excel 表。
我已经有来自Stackoverflow的代码
Option Explicit
Public Sub Move_Items()
'// Declare your Variables
Dim Inbox As Outlook.MAPIFolder
Dim SubFolder As Outlook.MAPIFolder
Dim olNs As Outlook.NameSpace
Dim Item As Object
Dim lngCount As Long
Dim Items As Outlook.Items
On Error GoTo MsgErr
'// Set Inbox Reference
Set olNs = Application.GetNamespace("MAPI")
Set Inbox = olNs.GetDefaultFolder(olFolderInbox)
Set Items = Inbox.Items
'// Loop through the Items in the folder backwards
For lngCount = Items.Count To 1 Step -1
Set Item = Items.Item(lngCount)
Debug.Print Item.Subject
If Item.Class = olMail Then
'// Set SubFolder of Inbox
Set SubFolder = Inbox.Folders("Temp")
'// Mark As Read
Item.UnRead = False
'// Move Mail Item to sub Folder
Item.Move SubFolder
End If
Next lngCount
MsgErr_Exit:
Set Inbox = Nothing
Set SubFolder = Nothing
Set olNs = Nothing
Set Item = Nothing
Exit Sub
'// Error information
MsgErr:
MsgBox "An unexpected Error has occurred." _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume MsgErr_Exit
End Sub
我希望代码读取活动工作表列,如下所示:
Subject.mail folder_name
A 1
B 2
C 3
例如,主题为“A”的收件箱中的邮件,则必须将该邮件放在文件夹“1”中。
如何循环播放?查看 Sheet1 并读取它必须移动到哪个子文件夹?
【问题讨论】:
-
您考虑过 Outlook 邮件规则吗?他们可以为您做到这一点。您可以使用非常具体的标准指定将邮件移动到何处。