遍历公用文件夹中的电子邮件时,Outlook VBA脚本运行时错误随机出现13 [英] outlook VBA script run-time error 13 randomly while iterating emails in a public folder

查看:133
本文介绍了遍历公用文件夹中的电子邮件时,Outlook VBA脚本运行时错误随机出现13的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个随机的运行时错误13(类型不匹配),执行以下子例程.此例程大部分时间都有效.在失败时,作为参数传入的文件夹是合法的.从调试器中可以看到,在运行时objitem缺少了某些字段.在调试器中达到断点后,我可以立即执行单步操作(重新执行有问题的行),并且没有错误.

I am receiving a random run-time error 13 (type mismatch) executing the following subroutine. This routine works most of the time. The Folder passed in as an argument is legitimate at the time of the failure. From what I can see in the debugger, the objitem is missing some of the fields during runtime. After it break-points in the debugger, I can immediately single-step (re-executing the offending line) and there is no error.

我尝试使用'on error goto'入睡,然后重试各行,并且该错误持续存在,直到在调试器中停止.

I have attempted using 'on error goto' to sleep then retry various lines, and the error persists until it stops in the debugger.

我还试图在For ii和For Each形式的循环命令之间进行切换.

I have also attempted changing between the For ii and For Each forms of the loop commands.

我也被防病毒软件暂时禁用了.

I have also temporarily disabled by anti-virus.

我正在遍历大量公用文件夹.我的Outlook客户端是在XP下运行的2003,并且已连接到Exchange服务器版本7654.

I am iterating over a large number of public folders. My outlook client is 2003 running under XP, and I am attached to Exchange server version 7654.

谁能告诉我我做不到的事情(或者我尝试做的事情是不可能的)吗?

Can anyone tell me what I am failing to do (or if what I am attempting is not possible)?

下面的代码根据@dmitry的建议进行了修改,现在可以使用.

Code below is modified per @dmitry suggestions and now works.

Sub SearchFolders(objFolder As Outlook.MAPIFolder)
    Dim objFolders As Outlook.Folders
    Dim subFolder As Outlook.MAPIFolder
    Dim Objitem As Outlook.MailItem
    Dim ii As Integer
    Dim ThisItem As Object
    Dim Items As Outlook.Items

' Recurse through all subfolders
    Set objFolders = objFolder.Folders
    For Each subFolder In objFolders
    Call SearchFolders(subFolder)
    Next subFolder

' Search the emails
    Set Items = objFolder.Items
    For ii = 1 To Items.Count
    Set ThisItem = Items.item(ii)
    If ThisItem.Class = olMail Then
        If VarType(ThisItem) = 9 Then GoTo NextdblLoop
        Set Objitem = ThisItem
        CheckEmailForErrorReports (objFolder.Items(ii))
        Set Objitem = Nothing
    End If
    Set ThisItem = Nothing
NextdblLoop:
    Next ii
    Set Items = Nothing
End Sub

推荐答案

首先,不要使用多点符号;在进入循环之前先缓存Items集合.

Firstly, do not use multiple dot notation; cache the Items collection before entering the loop.

第二,在使用完变量后立即释放它们

Secondly, release the variables as soon as you are done with them

    dim item As Object
    dim Items as Outlook.Items
    set Items = objFolder.Items
    For ii = 1 To Items.Count
        set item = Items.Item(ii)
        If item.Class = olMail Then
            If TypeName(item) <> "MailItem" Then
                'THIS CAN NEVER HAPPEN. The check above is sufficient
                MsgBox ("Type mismatch: object s/b MailItem and is " & TypeName(item))
                GoTo NextdblLoop
            End If
            Set objitem = item 
            CheckEmailForErrorReports (objitem)
            Set objitem = Nothing
        End If
        Set item = Nothing
NextdblLoop:
    Next ii
End Sub

这篇关于遍历公用文件夹中的电子邮件时,Outlook VBA脚本运行时错误随机出现13的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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