【问题标题】:Count Outlook VBA attachment计算 Outlook VBA 附件
【发布时间】:2014-05-22 08:36:43
【问题描述】:

您能否帮助我改进以下 VBA 代码,以便能够正确计算选定范围内的电子邮件 + 附件(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 

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

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

BR

加比

【问题讨论】:

    标签: vba outlook


    【解决方案1】:

    试试这个

    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
    

    【讨论】:

      猜你喜欢
      • 2023-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 2016-09-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多