gpt4 book ai didi

excel - 如果单元格的值为 = 1,则将电子邮件地址添加到 Outlook 电子邮件

转载 作者:行者123 更新时间:2023-12-04 21:02:22 28 4
gpt4 key购买 nike

我正在尝试向 E 列中带有“1”的任何人发送电子邮件寻求帮助。我有一个包含一系列员工及其电话号码的工作表。在他们的电话号码后面是他们想要收到通知的事件列表。如果我在他们的名字后面的一列中放置一个 1,我希望将他们的电子邮件地址添加到电子邮件中。

列标题类似于 A=Last Name、B=First name、C=Phone Number、D=Email Address、E=Event 1、F=Event 2、G=event 3 等等。

我能够获取电子邮件代码以从设定范围内提取所有电子邮件地址,但我无法弄清楚如何添加 if 命令以在事件列之一(E、F、G.. .)。它需要遍历整个范围,然后仅为那些在其中一个事件列中具有设定值的选定个人提取地址。

到目前为止,这是我的代码:

Dim OutApp As Object
Dim OutMail As Object
Dim strto As String, strcc As String, strbcc As String
Dim strsub As String, strbody As String
Dim emailRng As Range, cl As Range
Dim sTo As String

Set emailRng = Worksheets("Sheet1").Range("D1:D500")

For Each cl In emailRng
sTo = sTo & ";" & cl.Value
Next

sTo = Mid(sTo, 2)


Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)


strto = sTo

strcc = ""
strbcc = ""
strsub = "'NOTIFICATION' - " & "Notification"
strbody = "<img src=Z:\Logo2.jpg width=624 height=74>" & _
"<font size=2 font face=Verdana color=black>" & "<br>" & _
"The following notification was received:</B><br><br>" & _
"COPY AND PAST NOTIFICATION RECEIVED HERE" & "<br><br>" & _
"<b>Control Center</b><br><br>"


With OutMail
'.SentOnBehalfOfName = ""
.to = strto
.cc = strcc
.bcc = strbcc
.Subject = strsub
'You can add a file to the mail like this
.HTMLBody = strbody
.Display ' or use .Send
End With

Set OutMail = Nothing
Set OutApp = Nothing

最佳答案

基本答案是这样的:

For Each cl In emailRng
If cl.Offset(,1) = 1 Then sTo = sTo & ";" & cl.Value
Next

在这里,您正在检查是否检查了距电子邮件地址 1 列(列 E 中的事件 1)的通知。

但是,由于您声明可以有 n 个事件,因此您需要一种方法来确定您要为哪个事件发送电子邮件。我不知道您打算如何处理它,但是您可以例如从另一个 Sub 调用 Sub 并传递事件编号并将其用作偏移量。

所以
Sub EmailEvent()

SendEventEmail 1 'send event 1 email
SendEventEmail 2 'send event 2 email
SendEventEmail 3 'send event 3 email

End Sub

然后在您实际发送邮件的子中,它会说
Sub SendEventEmail(n as Long)
Rem n is the Event Number

Rem Your Code ...

For Each cl in emailRng
If cl.Offset(,n) = 1 Then sTo = sTo & ";" & cl.Value
Next

Rem Rest of code ...

End Sub

关于excel - 如果单元格的值为 = 1,则将电子邮件地址添加到 Outlook 电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33791893/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com