我基本上是在尝试为更大规模的宏创建报告。该报告将显示处理过的每封邮件以及在电子邮件中找到的附件。
我有以下代码可以使用,但不能为我提供.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"
Else
csv_report = "NO"
End If
If LCase(Right(.Attachments(i2).Filename, 4)) = ".pdf" Then
pdf_report = "YES"
Else
pdf_report = "NO"
End If
If LCase(Right(.Attachments(i2).Filename, 4)) = ".xls" Or LCase(Right(.Attachments(i2).Filename, 5)) = ".xlsx" Then
xls_report = "YES"
Else
xls_report = "NO"
End If
Next
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)
所以只需添加' GoTo'功能我能够回答我自己的查询。谢谢大家留下评论
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