简体   繁体   English

VBA Excel-如果一列中的单元格包含电子邮件地址,而另一列中的单元格是“ SOLD”,则发送电子邮件

[英]VBA Excel - If cell in one column contains email address and cell in another column is “SOLD” , send email

Just started experimenting with VBA today. 今天才刚刚开始尝试VBA。 Creating Excel sheet to track SOLD, PENDING, LOST that will allow salesmen to click a button to send a group email to one category at a time. 创建Excel工作表以跟踪“已售出”,“待处理”和“丢失”,这将使销售人员可以单击一个按钮来一次将一组电子邮件发送到一个类别。 After much searching I found some code that works well to send group email by checking a column to make sure a proper address is there. 经过大量搜索后,我发现一些代码可以很好地通过检查一列以确保发送正确的地址来发送组电子邮件。 I found some other code that I thought would check the "Job Status" column so that only the "SOLD" or whatever would be chosen for email. 我找到了一些我认为会检查“工作状态”列的代码,以便仅选择“已售出”或任何其他形式的电子邮件。 I am a clueless beginner and need help. 我是一个笨拙的初学者,需要帮助。 Here is the code that was working until I added the - If Sh.Cells(Target.Row, 7) = "PENDING" Then - part. 这是直到我添加了-If Sh.Cells(Target.Row,7)=“ PENDING”然后-部分之前一直有效的代码。 Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks! 谢谢!

Private Sub CommandButton1_Click()
Dim cell As Range
 Dim strto As String
 For Each cell In ThisWorkbook.Sheets("Sales 2013").Range("E3:E500")
 If cell.Value Like "?*@?*.?*" Then
    If Sh.Cells(Target.Row, 7) = "PENDING" Then
     strto = strto & cell.Value & ";"
    End If
 End If
 Next cell
 If Len(strto) > 0 Then strto = Left(strto, Len(strto) - 1)

Application.ScreenUpdating = False
 Set OutApp = CreateObject("Outlook.Application")
 OutApp.Session.Logon

 On Error GoTo cleanup
 Set OutMail = OutApp.CreateItem(0)
 On Error Resume Next
 With OutMail
 .To = "Anchor Sales"
 .Bcc = strto
 .Subject = "Enter subject here"
 .Body = "" ' EMPTY FOR NOW
 'USE THIS FOR ENTERING NAMES OF RECIPIENTS IN BODY TEXT "here"
 '"Dear" & Cells(cell.Row, "A").Value _
 & vbNewLine & vbNewLine & _
 "Enter body text " & _
 "here"
 'You can add files also like this
 '.Attachments.Add ("C:\test.txt")
 '.Send 'Or use Display
 .Display
 End With
 On Error GoTo 0
 Set OutMail = Nothing
cleanup:
 Set OutApp = Nothing
 Application.ScreenUpdating = True
End Sub

Private Sub CommandButton2_Click()

End Sub

Please help! 请帮忙!

of course I would prefer to send one mail per Person (if the recipients shall not know each other), but let's stay with your Problem. 当然,我希望每人发送一封邮件(如果收件人彼此之间不认识),但让我们来解决您的问题。

you only need minor changes: 您只需要进行少量更改:

Private Sub CommandButton1_Click()
Dim cell As Range
 Dim strto As String
 For Each cell In ThisWorkbook.Sheets("Sales 2013").Range("E3:E500")
 If cell.Value = "PENDING" Then strto = strto & cell.offset(0, 1).value & ";" 

I am not sure if you Need the part "If cell.Value Like "? 我不确定是否需要“ If cell.Value Like”部分? @? @? .?*" " or if that is from copy-paste from the code you found... If you Need it, the last line would have to be replaced by 。?*“”还是来自您发现的代码的复制粘贴...如果需要,则最后一行必须替换为

 If cell.Value Like "?*@?*.?*" and cell.Value = "PENDING" Then strto = strto & cell.offset(0, 1).value & ";"  

    'in Offset(0,1) I assume the mailadress is in the cell next to the cell tested for "pending" 
 Next cell
 If Len(strto) > 0 Then strto = Left(strto, Len(strto) - 1)

the rest as you have it. 剩下的就随你了。

the Problem was caused by 问题是由

    If Sh.Cells(Target.Row, 7) = "PENDING" Then

as you have no definition for "sh" - but you also don't need it. 因为您没有“ sh”的定义-但您也不需要它。

I hope this helps 我希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果Excel中单元格区域中的单元格包含电子邮件地址(@符号),我想将整个单元格文本移到其他列中 - If a cell in range of cells in Excel contains an email address (@ sign), I want to move whole cell text into a different column Excel VBA send to email address by looking for header "Email" and sending email to first cell beneath matching header - Excel VBA send to email address by looking for header "Email" and sending email to first cell beneath matching header VBA当单元格等于另一个工作表中的单元格时发送电子邮件 - VBA Send email when cell equals cell in another sheet Excel VBA 如果其他列中的单元格包含值,则向单元格添加注释 - Excel VBA Add comment to cell if cell in other column contains value Excel VBA电子邮件单元格值 - Excel VBA email cell value 发送电子邮件到单元格中的电子邮件地址(如果有) - Send email to email address in cell, if any Excel VBA 按钮根据单元格值保存工作簿并发送 email - Excel VBA button to save workbook based on cell values and send email Excel VBA代码从单元格中读取用户名,然后向该用户发送电子邮件 - Excel VBA code to read a username from a cell then send an email to that user VBA验证列中是否包含电子邮件 - VBA validating if column contains email VBA从一个Excel搜索到另一个Excel并显示单元格地址 - VBA to search from one excel to another excel and display cell address
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM