计算Outlook VBA附件 [英] Count Outlook VBA attachment

查看:78
本文介绍了计算Outlook VBA附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能帮我改进下面的VBA代码,以便正确计数选定范围内的电子邮件和附件吗(2010年展望)

Can you help me to improve the below VBA code to be able to correctly count e-mails + attachments form a selected range (outlook 2010)

Sub CountAttachmentsMulti()

Set mySelect = Outlook.ActiveExplorer.Selection
For Each Item In mySelect
j = Item.Attachments.Count + j
i = i + 1
Next Item
MsgBox "Selected " & i & " messages with " & j & " attachements"

End Sub 

这是代码的问题所在,就是将签名中的图片也算作附件,并给出错误的计数,这意味着比实际附件更多

That is the code the problem is that counts also as attachments the picture in the signatures and give a wrong count meaning more attachments then the actually are

您能帮助修改代码以绕过签名中的图像计数

Can you help to amend the code to bypass from counting the images in signatures

BR

Gabi

推荐答案

尝试一下

Sub CountAttachmentsValid()

Dim olkItem As Outlook.mailitem
Dim olkAttachment As Outlook.attachment

Dim strFilename As String
Dim strExtension As String
Dim lngExtIndex As Long
Dim strBaseFilename As String
Dim cnt As Long

Dim mySelect As Selection

Dim iExt As Long
Dim validExtString As String
Dim validExtArray() As String

validExtString = ".doc .docx .xls .xlsx .msg .pdf .txt" ' <---- Update as needed
validExtArray = Split(validExtString, " ")

Set mySelect = Outlook.ActiveExplorer.Selection

For Each olkItem In mySelect

    For Each olkAttachment In olkItem.Attachments

        On Error GoTo cannotPerformOperation
        strFilename = olkAttachment.FileName
        lngExtIndex = InStrRev(strFilename, ".")
        strBaseFilename = Left(strFilename, lngExtIndex - 1)
        strExtension = Mid(strFilename, lngExtIndex)

        For iExt = 0 To UBound(validExtArray)

            If LCase(strExtension) = LCase(validExtArray(iExt)) Then
                cnt = cnt + 1
                Exit For
            End If

        Next iExt

skipped:

    Next olkAttachment

Next olkItem

GoTo exiting

cannotPerformOperation:
'Debug.Print " ** " & olkAttachment.DisplayName & " not counted"
Resume skipped

exiting:
    MsgBox "Selected " & mySelect.count & " messages with " & cnt & " recognized attachments"

End Sub

这篇关于计算Outlook VBA附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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