Vba Outlook附件计数显示不正确的数字

Vba Outlook附件计数显示不正确的数字,vba,email,outlook,Vba,Email,Outlook,我试图循环浏览所选邮件中的所有附件项目,但附件数量产生了荒谬的价值 Sub ABU_out() Dim olapp As Outlook.Application Dim olmail As Outlook.MailItem Dim item As Object Dim olath As Outlook.Attachments Set olapp = GetObject(, "Outlook.Application") Set olmail = olapp.ActiveExplorer.

我试图循环浏览所选邮件中的所有附件项目,但附件数量产生了荒谬的价值

Sub ABU_out()

Dim olapp As Outlook.Application
Dim olmail As Outlook.MailItem
Dim item As Object
Dim olath As Outlook.Attachments




Set olapp = GetObject(, "Outlook.Application")
Set olmail = olapp.ActiveExplorer.Selection(1)


If Not olmail.Attachments.Count = 0 Then

Debug.Print olmail.Attachments.Count

        For Each olath In olmail.Attachments

            If InStr(LCase(olath.FileName), "certificate") Then

                If InStr(LCase(olath.FileName), "endorsement") = 0 Then

                    Debug.Print olath.FileName

                    olath.SaveAsFile "C:\Users\mohit.bansal\Desktop\Automations\ABU\Slips Sample\" & olath.FileName

                End If

            End If

        Next

End If



End Sub

当我选择一封包含2个项目的邮件时,会出现问题“debug.print”显示为3,如果邮件包含3个项目,则显示为5。olath中出现错误表示它没有什么不确定代码中有什么错误,我在私人事件中使用了类似的代码,运行平稳。

发现了错误。。。。我将olath声明为outlook.attachments,但如果我将其声明为object,它将正常工作

这里有一个额外的s。Dim olath作为Outlook.attachments不要忘记图像也是附件。我建议在驳回指控之前调查每个附件。