Excel 如何在循环验证后发送带有字符串列表的电子邮件
我是这个论坛的新手。我对excel中的vba宏有点问题。也许这对你来说并不难,但我对vba完全陌生。我有两列:带选项的列“A”和带字符串的列“B”。我想发送一封包含“B”字符串列表的电子邮件,其中包含所有在“A”中具有“是”值的字符串(逐行)Excel 如何在循环验证后发送带有字符串列表的电子邮件,excel,vba,outlook,Excel,Vba,Outlook,我是这个论坛的新手。我对excel中的vba宏有点问题。也许这对你来说并不难,但我对vba完全陌生。我有两列:带选项的列“A”和带字符串的列“B”。我想发送一封包含“B”字符串列表的电子邮件,其中包含所有在“A”中具有“是”值的字符串(逐行) 到目前为止,我的最佳结果是发送一组不同的邮件,每个“是”“a”值只有一个“B”字符串(即,如果我有3个“是”值,我将获得3封邮件,每个邮件都有正确的“B”字符串)。请尝试以下代码: Sub Alert() ActiveSheet.UsedRange
到目前为止,我的最佳结果是发送一组不同的邮件,每个“是”“a”值只有一个“B”字符串(即,如果我有3个“是”值,我将获得3封邮件,每个邮件都有正确的“B”字符串)。请尝试以下代码:
Sub Alert()
ActiveSheet.UsedRange.Select
On Error Resume Next
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim list As String
Dim element As Variant
Application.ScreenUpdating = False
Do While Trim(Cells(cell.Row, "A").Value) = ""
On Error GoTo alertmail
For Each cell In Columns("A").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value = "yes" Then
element = Cells(cell.Row, "B").Value
list = list & vbNewLine & element
End If
Next cell
Loop
alertmail:
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "to@xyz.com"
.Subject = "Alert"
.Body = "Your yes list is" & vbNewLine & list
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Exit Sub
Application.ScreenUpdating = True
End Sub
请尝试以下代码:
Sub Alert()
ActiveSheet.UsedRange.Select
On Error Resume Next
Dim OutApp As Object
Dim OutMail As Object
Dim cell As Range
Dim list As String
Dim element As Variant
Application.ScreenUpdating = False
Do While Trim(Cells(cell.Row, "A").Value) = ""
On Error GoTo alertmail
For Each cell In Columns("A").Cells.SpecialCells(xlCellTypeConstants)
If cell.Value = "yes" Then
element = Cells(cell.Row, "B").Value
list = list & vbNewLine & element
End If
Next cell
Loop
alertmail:
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "to@xyz.com"
.Subject = "Alert"
.Body = "Your yes list is" & vbNewLine & list
.Display
End With
On Error GoTo 0
Set OutMail = Nothing
Exit Sub
Application.ScreenUpdating = True
End Sub
在出现错误时删除,然后继续下一步并修复错误。此行隐藏所有错误消息,但错误仍会发生。我建议在此过程中安装一个正确的错误处理:在错误恢复下一步时删除
,然后修复错误。此行隐藏所有错误消息,但错误仍会发生。我建议在这个过程中安装一个正确的错误处理:对不起,我还有一个关于宏的问题。如果我的“yes”值在“A”中被写为字符串,则宏可以正常工作,但如果“yes”值是从单元格“A”中的函数获得的(es.A1=If(C1=1;“yes”;“no”)),则列“C”条件选项不起作用。为什么?好的,我解决了为列(“A”)中的每个单元格替换。为列(“A”)中的每个单元格替换Cells.SpecialCells(xlCellTypeConstants)
。为列(“A”)中的每个单元格替换。单元格
对不起,但我还有关于宏的第二个问题。如果我的“yes”值在“A”中被写为字符串,则宏可以正常工作,但如果“yes”值是从单元格“A”中的函数获得的(es.A1=If(C1=1;“yes”;“no”)),则列“C”条件选项不起作用。为什么?好的,我解决了为列(“A”)中的每个单元格替换。单元格。特殊单元格(xlCellTypeConstants)
为列(“A”)中的每个单元格替换。单元格