我试图遍历所选邮件中的所有附加项目,但附件计数产生了荒谬的价值。
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说没什么不确定代码中有什么问题,我在私人活动中使用了类似的代码,这些代码运行顺畅。
答案 0 :(得分:0)
发现错误....我将olath声明为outlook.attachments,而如果我将其声明为对象则有效。