热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

参照单元格在.send或.display之间进行选择的Outlook电子邮件的VBA代码是什么

我想使用vba发送前景电子邮件,允许用户在.send或。显示关于一个单

我想使用vba发送前景电子邮件,允许用户在
.send或
。显示
关于一个单元格。

有办法吗?


如何实现此目的的示例如下,假设A列包含电子邮件地址,B列包含“显示”或“发送”:

Sub LoopThroughRows_SendEmail()
Dim OutApp As Object: Set OutApp = CreateObject("Outlook.Application")
Dim OutMail As Object: Set OutMail = OutApp.CreateItem(0)
Dim i As Long
Dim ws As Worksheet: Set ws = ThisWorkbook.Worksheets("Sheet1")
'declare and set the worksheet you are working with
For i = 2 To ws.UsedRange.Rows.Count
'loop from Row 2 To Last Row in UsedRange
With OutMail
.To = ws.Cells(i,"A").Value 'get email address from Column A
.CC = ""
.BCC = ""
.Subject = "Subject"
.Body = "Please contact us to discuss blah blah blah......"
If ws.Cells(i,"B").Value = "Display" Then
'if column B contains "Display" then .Display,else .Send
.Display
ElseIf ws.Cells(i,"B").Value = "Send" Then
.Send
End If
End With
Next i
End Sub

推荐阅读
author-avatar
丢失的面包树
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有