excel - 如何遍历表格并将电子邮件发送给相应的用户
问题描述
我有一张桌子:
程序需要循环发送电子邮件到 NAV30 和 FED09。
Nav30 应该只接收表格的第 1 行和第 3 行。FED09 应该只接收第 2 行。
我找到了一个有效但不执行循环和抓取的代码
Sub Test2()
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim answer As String
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
answer = MsgBox("Are you sure you want to send these emails?", vbYesNo + vbQuestion)
If answer = vbYes Then
For Each cell In Columns("AC").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value Like "?*@?*.?*" And _
LCase(Cells(cell.Row, "AD").Value) = "oui" _
And LCase(Cells(cell.Row, "AE").Value) <> "sent" Then
Set OutMail = OutApp.CreateItem(olMailItem)
On Error Resume Next
With OutMail
.To = cell.Value
.Subject = "blabla"
.BodyFormat = olFormatHTML
.HTMLBody = "blabla"
.Display
End With
On Error GoTo 0
Cells(cell.Row, "AE").Value = "sent"
Set OutMail = Nothing
End If
Next cell
Else
Exit Sub
End If
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
解决方案
推荐阅读
- python - 是否有代码我可以在程序中运行以使用已知密码连接到安全 wifi
- android - 如何使 TextView 的文本使用我给它的样式?
- php - PHP foreach 循环练习
- php - 如何在 symfony 中使用多个唯一实体
- java - 如何使用 Microsoft graph 更新当前会议事件?(使用补丁方法)
- javascript - 如何使必须检查至少一个单选按钮,如果不是,不允许用户转到下一个问题?
- teamcity - 将参数添加到 TeamCity
- html - 我想在中心对齐主导航菜单的内容
- php - 使用 ajax 和 php 刷新 b 内容
- javascript - 如何添加子对象的值并将其推送到相应的父对象