下面的宏旨在获取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
答案 0 :(得分:0)
检查以下代码。我刚刚添加了If Else
块来检查Attachment.count>这就是它。
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
答案 1 :(得分:0)
经过多次尝试实施此方案后,我没有成功。所以我想在这个宏之后添加一个替代方法。
这个宏只是更大规模宏的一小部分,但基本上当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