Outlook 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
End Sub
问题是我的收件箱中有744个项目,它通过8或9,然后给我一个&#34;类型不匹配&#34;。当我调试时,它会标记&#34; Next olItem&#34;当我检查&#34; olItem&#34;的价值时它解决了&#34;没有&#34;。
我做错了什么?
答案 0 :(得分:3)
您假设您只能在文件夹中拥有MailItem对象。您还可以使用ReportItem,MettingRequestItem等。将olItem声明为通用对象,并将Class属性检查为43(olMail)。