【发布时间】:2015-05-06 12:18:19
【问题描述】:
我基本上是在尝试为我的更大规模的宏创建报告。该报告将显示处理的每封邮件以及在电子邮件中找到的附件。
我可以使用以下代码,但没有为我提供仅适用于 .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
【问题讨论】:
-
我看到的最大问题是你没有使用
For Each循环。 -
您是否尝试调试代码并查看 FileName 实际值?
-
如何构建“For Each”循环?我会尝试使用 msgBox 来调试代码
-
Dim Att as Attachment和For Each Att in .Attachments与Next Att在循环结束! ;) 并在循环中Att.FileName -
你应该加入你的 If
.Attachments.Count = 0 Then和If .Attachments.Count > 0 Then到:如果.Attachments.Count <= 0 Then和Else
标签: excel vba email outlook email-attachments