0

展望 2010 VBA。尝试在我的所有文件夹中搜索标记的邮件。创建了这个:

Private Sub flagrecurse(fold As Variant)

Dim olItem As MailItem
Dim nxtfold As Folder
Dim olFoldVar As Variant

'Test for which folder is being checked
MsgBox (fold.Name)

If fold.Folders.Count > 0 Then
    For Each nxtfold In fold.Folders
        Set olFoldVar = nxtfold
        flagrecurse olFoldVar
    Next nxtfold
Else
    For Each olItem In fold.Items
         'Test for which item is being checked
         If TypeName(olItem) = "MailItem" Then
            MsgBox (olItem.Subject)
            With olItem
                If .FlagRequest <> "" Or .IsMarkedAsTask Then
                    '.TaskDueDate = Now
                    'Sets a reminder today, in case one wasn't set
                    If Not (.ReminderSet) Then
                        .ReminderSet = True
                        .ReminderTime = Now + 2 / 24
                        .Save
                    End If
                End If
            End With
        End If
    Next olItem
End If

结束子

问题是我的收件箱中有 744 个项目,它通过 8 或 9,然后给我一个“类型不匹配”。当我调试时,它会标记“下一个 olItem”,当我检查“olItem”的值时,它会解析为“无”。

我究竟做错了什么?

4

1 回答 1

3

您假设文件夹中只能有 MailItem 对象。您还可以拥有 ReportItem、MettingRequestItem 等。将 olItem 声明为通用对象并检查 Class 属性为 43 (olMail)。

于 2014-06-23T18:43:44.447 回答