mailitem循环中的类型不匹配 [英] Type Mismatch in mailitem loop

查看:90
本文介绍了mailitem循环中的类型不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Outlook 2010 VBA. 尝试在我所有的文件夹中搜索已标记的邮件. 创建此:

Outlook 2010 VBA. Trying to search for flagged messages in all my folders. Created this:

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"的值时,它将解析为无".

The issue is I have 744 items in my Inbox, it gets through 8 or 9, then gives me a "Type Mismatch". When I'm debugging, it flags "Next olItem" and when I check the value of "olItem" it resolves to "nothing".

我在做什么错了?

推荐答案

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

You are assuming that you can only have MailItem objects in the folder. You can also have ReportItem, MettingRequestItem, etc. Declare olItem as a generic Object and check the Class property to be 43 (olMail).

这篇关于mailitem循环中的类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆