【发布时间】:2021-10-17 18:04:17
【问题描述】:
我想将 Outlook RSS 源中的“未读电子邮件”复制到 Excel。这些复制的电子邮件应在 Outlook 中标记为“已读”。
下面的代码返回
无效的过程调用或参数。
Private Sub run_btn_Click()
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.GetDefaultFolder(olfolderrssfeeds).Folders("Folder Name")
If Folder.items.Restrict("[UnRead] = True").Count = 0 Then
MsgBox "No Unread email", vbInformation, "Congratulation!"
End If
i = 1
For Each OutlookMail In Folder.items.Restrict("[UnRead] = True")
Range("eMail_subject").Offset(i, 0).Value = Left(OutlookMail.Subject, 11)
Range("eMail_date").Offset(i, 0).Value = OutlookMail.ReceivedTime
Range("eMail_text").Offset(i, 0).Value = OutlookMail.Body
i = i + 1
Next OutlookMail
If Folder.items.Restrict("[Unread] = True") Then
Folder.items.UnRead = False
Folder.items.Save
End If
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing
End Sub
【问题讨论】:
-
调试器到底停在哪里?
-
真的有一个叫“文件夹名”的文件夹吗?另外,最后一次 Restrict 调用是否应该测试 Restrict.Count?