如何基于Excel中的单元格值自动发送电子邮件?
假设您要基于Excel中指定的单元格值通过Outlook向特定收件人发送电子邮件。 例如,当工作表中单元格D7的值大于200时,将自动创建一封电子邮件。 本文介绍了一种VBA方法,可帮助您快速解决此问题。
使用VBA代码根据单元格值自动发送电子邮件
请执行以下操作以根据Excel中的单元格值发送电子邮件。
1.在工作表中,您需要根据其单元格值(此处表示单元格D7)发送电子邮件,右键单击工作表选项卡,然后选择 查看代码 从上下文菜单中。 看截图:
2.在弹出 Microsoft Visual Basic应用程序 窗口,请将以下VBA代码复制并粘贴到工作表代码窗口中。
VBA代码:根据Excel中的单元格值通过Outlook发送电子邮件
Dim xRg As Range
'Update by Extendoffice 2018/3/7
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
Set xRg = Intersect(Range("D7"), Target)
If xRg Is Nothing Then Exit Sub
If IsNumeric(Target.Value) And Target.Value > 200 Then
Call Mail_small_Text_Outlook
End If
End Sub
Sub Mail_small_Text_Outlook()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Hi there" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2"
On Error Resume Next
With xOutMail
.To = "Email Address"
.CC = ""
.BCC = ""
.Subject = "send by cell value test"
.Body = xMailBody
.Display 'or use .Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
:
1)。 在 VBA 代码中, D7 和 值> 200 是您将基于其发送电子邮件的单元格和单元格值。
2)。 请根据需要更改电子邮件正文 邮件正文 代码中的一行。
3)。 将电子邮件地址替换为行中的收件人电子邮件地址 .To =“电子邮件地址”.
4)。 并根据需要指定抄送和密送收件人 .CC =“” 和 密件副本=“” 部分。
5)。 最后更改邮件主题 .Subject =“按单元格值测试发送”.
3。 按 其他 + Q 键一起关闭 Microsoft Visual Basic应用程序 窗口。
从现在开始,当您在单元格D7中输入的值大于200时,将在Outlook中自动创建带有指定收件人和正文的电子邮件。 您可以点击 提交 按钮发送此电子邮件。 看截图:
:
1.仅当您使用Outlook作为电子邮件程序时,VBA代码才起作用。
2.如果在单元格D7中输入的数据是文本值,则电子邮件窗口也会弹出。
根据在Excel中创建的邮件列表的字段,通过Outlook轻松发送电子邮件:
发电子邮件 实用程序 Kutools for Excel 帮助用户基于Excel中创建的邮件列表通过Outlook发送电子邮件。
立即下载并试用! (30 天免费试用)
相关文章:
- 当工作簿保存在Excel中时,如何通过Outlook发送电子邮件?
- 如果在Excel中修改了某个单元格,该如何发送电子邮件?
- 如果在Excel中单击按钮,如何发送电子邮件?
- 如果在Excel中已达到到期日期,如何发送电子邮件?
- 如果在Excel中更新了工作簿,如何发送电子邮件提醒或通知?
最佳办公生产力工具
🤖 | Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行 | 生成代码 | 创建自定义公式 | 分析数据并生成图表 | 调用 Kutools 函数... |
热门特色: 查找、突出显示或识别重复项 | 删除空白行 | 合并列或单元格而不丢失数据 | 不使用公式进行四舍五入 ... | |
超级查询: 多条件VLookup | 多值VLookup | 跨多个工作表的 VLookup | 模糊查询 .... | |
高级下拉列表: 快速创建下拉列表 | 依赖下拉列表 | 多选下拉列表 .... | |
列管理器: 添加特定数量的列 | 移动列 | 切换隐藏列的可见性状态 | 比较范围和列 ... | |
特色功能: 网格焦点 | 设计图 | 大方程式酒吧 | 工作簿和工作表管理器 | 资源库 (自动文本) | 日期选择器 | 合并工作表 | 加密/解密单元格 | 按列表发送电子邮件 | 超级筛选 | 特殊过滤器 (过滤粗体/斜体/删除线...)... | |
前 15 个工具集: 12 文本 工具 (添加文本, 删除字符,...) | 50+ 图表 类型 (甘特图,...) | 40+ 实用 公式 (根据生日计算年龄,...) | 19 插入 工具 (插入二维码, 从路径插入图片,...) | 12 转化 工具 (小写金额转大写, 货币兑换,...) | 7 合并与拆分 工具 (高级组合行, 分裂细胞,...) | ... 和更多 |
使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。 单击此处获取您最需要的功能...
Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松
- 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
- 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
- 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Sort comments by
#44939
This comment was minimized by the moderator on the site
0
0
#44976
This comment was minimized by the moderator on the site
Report
0
0
#44542
This comment was minimized by the moderator on the site
0
0
#44036
This comment was minimized by the moderator on the site
0
0
#43504
This comment was minimized by the moderator on the site
0
0
#43525
This comment was minimized by the moderator on the site
Report
0
0
#43449
This comment was minimized by the moderator on the site
0
0
#43540
This comment was minimized by the moderator on the site
Report
0
0
#43409
This comment was minimized by the moderator on the site
Report
0
0
#43408
This comment was minimized by the moderator on the site
Report
0
0
#42975
This comment was minimized by the moderator on the site
0
0
#42909
This comment was minimized by the moderator on the site
0
0
#42819
This comment was minimized by the moderator on the site
Report
0
0
There are no comments posted here yet