【发布时间】:2015-05-12 10:43:52
【问题描述】:
下面的宏旨在接收 x 数量的电子邮件,计算每封邮件中有多少附件,然后定位某些文件格式。然后它将记录在某个 Excel 电子表格中找到的内容。
宏运行良好,但我现在想在另一个场景中添加。我要添加的场景是,如果一封电子邮件有超过 1 个 .csv 文件,则应将其记录为“多个”而不是“是”。
有没有人有任何想法来实现这个场景?
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
【问题讨论】:
-
对不起,如果我没有说清楚。但这会导致包含 1 个 .csv 文件的电子邮件显示为“多个”。我希望它在 1 时保持为“是”,但在超过 1 时保持为“多个”
-
在下面查看我的答案。
标签: email excel outlook email-attachments vba