Excel 中记录的电子邮件附件

Email attachments recorded in Excel

下面的宏旨在获取 x 封电子邮件,计算每封邮件中有多少个附件,然后定位特定的文件格式。然后它将在某个 excel 电子表格中记录它发现的内容。

宏运行完美,但我现在想添加另一个场景。我要添加的场景是,如果一封电子邮件有超过 1 个 .csv 文件,则应将其记录为 "Multiple" 而不是 "YES".

有没有人有任何想法来实现这个场景?

        If .Attachments.Count = 0 Then
        csv_report = "NO"
        pdf_report = "NO"
        xls_report = "NO"
        End If

        If .Attachments.Count > 0 Then
        For i2 = 1 To .Attachments.Count
        If LCase(Right(.Attachments(i2).Filename, 4)) = ".csv" Then
        csv_report = "YES"
        GoTo CSVyes        'if a .csv file is found, it skips to the PDF attachment checker
        Else
        csv_report = "NO"
        End If
        Next

CSVyes:
        For i2 = 1 To .Attachments.Count
        If LCase(Right(.Attachments(i2).Filename, 4)) = ".pdf" Then
        pdf_report = "YES"
        GoTo PDFyes        'if a .pdf file is found, it skips to the XLS attachment checker
        Else
        pdf_report = "NO"
        End If
        Next

PDFyes:
        For i2 = 1 To .Attachments.Count
        If LCase(Right(.Attachments(i2).Filename, 4)) = ".xls" Or LCase(Right(.Attachments(i2).Filename, 5)) = ".xlsx" Or UCase(Right(.Attachments(i2).Filename, 4)) = ".XLS" Then
        xls_report = "YES"
        GoTo XLSyes        'if a .xls file is found, it skips to the end of the checks
        Else
        xls_report = "NO"
        End If
        Next

XLSyes:
        End If

        Sheets("Mail Report").Activate
        Range("C65000").End(xlUp).Offset(1).Value = csv_report
        Range("D65000").End(xlUp).Offset(1).Value = pdf_report
        Range("E65000").End(xlUp).Offset(1).Value = xls_report

        subject_line = mail.Subject
        Range("A65000").End(xlUp).Offset(1).Value = subject_line

检查下面的代码。我刚刚添加了 If Else 块来检查 Attachment.count > 1。就是这样。

If .Attachments.Count > 0 Then
    For i2 = 1 To .Attachments.Count
    If LCase(Right(.Attachments(i2).Filename, 4)) = ".csv" Then
    If .Attachments.Count > 1
       csv_report = "MULTIPLE"
    Else
       csv_report = "YES"
    End If
    GoTo CSVyes        'if a .csv file is found, it skips to the PDF attachment checker
    Else
    csv_report = "NO"
    End If
    Next

在多次尝试实现这个场景之后,我没有成功。所以我想在这个宏之后放一个替代方法。

这个宏只是一个更大规模宏的一小部分,但基本上当 B 列中有空白时,我会将 "YES" 替换为 "Multiple",这足以满足结果.

Dim kk As Long

Sheets("Mail Report").Activate
LastRow = Cells(Rows.Count, 1).End(xlUp).Row
For kk = 1 To LastRow
If IsEmpty(Cells(kk, 2)) Then
    Cells(kk, 2) = MAIN_PATH & "For Resolution\" & "multiple_csv\"
    Cells(kk, 3) = "MULTIPLE"
End If
Next kk