【发布时间】:2019-10-25 13:47:16
【问题描述】:
我的工作表“Volglijst”包含一个列表,其中包含已注册发送的所有包裹。 当供应商或快递员取件时,收货服务会记录取件日期和取件人。
当他们关闭文件时,会出现一个弹出窗口,询问他们是否要向请求发送的人发送电子邮件确认。 当他们选择是时,VBA 应检查工作表“Volglijst”中的所有行,其中 B 列和 Q 列中有日期,并且 S 列为空(这 3 个条件应同时适用,如果没有,则没有电子邮件需要发送)。
我正在让我的 Outlook 启动并创建一封新电子邮件,但它仍然是空的。 正文适用于其他电子邮件,仅对单元格内容的引用进行了调整以匹配条件适用的行。
Dim OutApp As Object
Dim OutMail As Object
Dim i As Long
Dim t As Range
Dim WkSht As Worksheet
Dim strbody As String
Set WkSht = Sheets("Volglijst")
For i = 1 To 999
If WkSht.Cells(i, 2).Value <> "" And WkSht.Cells(i, 17).Value <> "" And WkSht.Cells(i, 19).Value = "" Then
Dim rng As Range
With Application.Intersect(WkSht.Rows(i), WkSht.UsedRange)
Set rng = WkSht.Range(WkSht.Cells(i, 3), .Cells(.Cells.Count))
End With
If rng Is Nothing Then
Exit Sub
End If
End If
Next
On Error Resume Next
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "<font size=""3"" face=""Calibri"">" & _
"Beste Collega,<br><br>" & _
"Uw pakket met nummer <B>" & WkSht.Cells(WkSht.Rows(i), 1).Value & "</B> werd <B>" & WkSht.Cells(WkSht.Rows(i), 17).Value & "</B> opgehaald door <B>" & WkSht.Cells(WkSht.Rows(i), 16).Value & "</B>.<br>" & _
"Bijkomende opmerkingen goederenontvangst: <B>" & WS.Cells(WkSht.Rows(i), 18).Value & "</B>.<br>" & _
"<br><br>In geval van vragen gelieve contact op te nemen." & _
"<br><br> Met vriendelijke groeten, </font>"
On Error Resume Next
With OutMail
.To = WS.Cells(WkSht.Rows(i), 5).Value
.CC = ""
.BCC = ""
.Subject = "Ophaling pakket " & WS.Cells(i, 1).Value & ""
.HTMLBody = strbody
.Display 'or use .Send
End With
将为每行发送一封单独的电子邮件,列 B ""; column Q "", Column S = "" ,并且收件人是该行中 E 列的电子邮件地址。电子邮件正文中的详细信息也应来自适用的行。
【问题讨论】:
-
注释掉
On Error Resume Next- 您是否收到错误消息以及错误消息是什么? -
另外,你还没有提到问题是什么?
-
我会强烈建议对此进行划分,其中一个子例程约束 Excel 活动,一个单独的 Outlook 活动;这将有助于整体故障排除。尽可能设置范围,或将值保存在要在电子邮件中使用的变量中,因为这样可以避免在两个应用程序之间来回切换。
-
@Zac,邮箱为空数据未加载
标签: excel vba email cell onchange