【发布时间】:2021-02-03 14:53:38
【问题描述】:
我需要将工作表每一行的内容邮寄到“U”列中的电子邮件地址。程序需要验证“需要发送”(V 列)以及是否已经“通过电子邮件发送”(W 列)。
有一个类似的问题,但对我没有帮助。
一些细节:
- 电子邮件地址列(U 列)是一个公式,它使用另一个工作表中的 VLOOKUP 公式搜索电子邮件。
- 宏运行(无调试),但没有任何反应。未创建邮件草稿。
- 我尝试只使用一个条件,它会为整个列表创建所有草稿(似乎工作正常)
Sub email()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
For Each cell In Worksheets("query_export_results").Columns("U").Cells.SpecialCells(xlCellTypeFormulas)
Set OutMail = OutApp.CreateItem(0)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "V").Value) = "Y" And _
LCase(Cells(cell.Row, "W").Value) = "" Then
With OutMail
.To = Cells(cell.Row, "U").Value
.Subject = "Notificação de Não Conformidade | Non-Compliance Notification"
.Body = "Notificação de Registro de Não Conformidade."
.display
'.Send
End With
Cells(cell.Row, "W").Value = "sent"
Set OutMail = Nothing
End If
Next cell
'Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
【问题讨论】:
-
您能否更清楚地解释“我尝试仅使用一个条件,它会为整个列表创建所有草稿(似乎工作正常)”是什么意思?什么是“一个条件”?
-
您好,先生!谢谢回答。我的意思是在“If cell.Value Like”?*@?*.?*“And _”这一行上,如果我删除“And _”并且不使用其他两个后续行,它就可以工作。但为工作表的所有行创建草稿。
-
我认为问题出在
LCase(Cells(cell.Row, "W").Value) = ""当单元格为空时,excel 无法将其转换为小写。试试Cells(cell.Row, "W")=""
标签: excel vba email conditional-statements