[英]Send email to email address in cell, if any
I have three columns("O", "Q", "S") that use VLOOKUP to get the email address from people's names input.我有三列(“O”、“Q”、“S”),它们使用 VLOOKUP 从输入的人名中获取电子邮件地址。 I want these people to all be emailed one email with some details.我希望这些人都收到一封电子邮件,其中包含一些详细信息。
I don't want this code to run if there are no email values in any of the three columns.如果三列中的任何列中都没有电子邮件值,我不希望此代码运行。 I'd like the code to run if any of the three columns has an email address.如果三列中的任何一列有电子邮件地址,我希望代码运行。
This code checks if a cell contains an email address and then sends that email address an email.此代码检查单元格是否包含电子邮件地址,然后向该电子邮件地址发送电子邮件。 I need this for all three of the cells & I need them to all be emailed together.我需要所有三个单元格都需要这个,我需要将它们全部通过电子邮件发送。
If emailbox.Value = True Then
On Error Resume Next
i = ActiveCell.Row 'VLOOKUP
Sheet2.Cells(i, 15).Value = Application.WorksheetFunction.VLookup(Sheet2.Cells(i, 14).Value, Sheet3.Range("AMS"), 2, 0)
On Error Resume Next
i = ActiveCell.Row 'VLOOKUP
Sheet2.Cells(i, 17).Value = Application.WorksheetFunction.VLookup(Sheet2.Cells(i, 16).Value, Sheet3.Range("AQE"), 2, 0)
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
For Each cell In Sheet2.Range("O" & ActiveCell.Row)
If cell.Value Like "?*@?*.?*" Then 'Check cell for email address
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = cell.Value
.Subject = "SUBJECT"
.Body = "Dear...."
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
sent.Visible = True
Else
End If
Next cell
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End If
Loop through each cell in column O
, and test all three cells for an email, when it encounters an email it will execute the rest of the code, and exit the inner loop.循环遍历column O
每个单元格,并测试所有三个单元格中是否有一封电子邮件,当它遇到一封电子邮件时,它将执行其余代码,并退出内部循环。
Dim cel As Range, lRow As Long, x As Long
lRow = ActiveSheet.Cells(Rows.Count, 15).End(xlUp).Row
For Each cel In Range("O2:O" & lRow)
For x = 15 To 19 Step 2 'loop through each cell in the active row
If Cells(cel.Row, x).Value Like "?*@?*.?*" Then
'email .To = Cells(cel.Row, x).Value
Exit For 'exits the inner loop when the condition is met
End If
Next x
Next cel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.