VBA Excel-如果一列中的单元格包含电子邮件地址,而另一列中的单元格是& quot; SOLD&"., 发送电子邮件 [英] VBA Excel - If cell in one column contains email address and cell in another column is "SOLD" , send email

查看:75
本文介绍了VBA Excel-如果一列中的单元格包含电子邮件地址,而另一列中的单元格是& quot; SOLD&"., 发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天就开始尝试使用VBA.创建Excel工作表以跟踪已售出",待处理"和丢失",这将使推销员可以单击一个按钮来一次将群组电子邮件发送到一个类别.经过大量搜索后,我发现一些代码可以很好地通过检查一列以确保发送正确的地址来发送组电子邮件.我找到了一些我认为会检查工作状态"列的代码,以便仅选择已售出"或任何其他形式的电子邮件.我是一个笨拙的初学者,需要帮助.这是一直有效的代码,直到我添加了-If Sh.Cells(Target.Row,7)="PENDING"然后-部分.任何帮助将不胜感激.谢谢!

Just started experimenting with VBA today. 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. 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. 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

请帮助!

推荐答案

当然,我希望每人发送一封邮件(如果收件人之间不会认识的话),但让我们解决您的问题.

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 & ";" 

我不确定您是否需要"If cell.Value like? @?.?*"部分,或者是从发现的代码中复制粘贴而来...如果需要,最后一行必须替换为

I am not sure if you Need the part "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)

剩下的一切.

问题是由

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

因为您没有"sh"的定义-但您也不需要它.

as you have no definition for "sh" - but you also don't need it.

我希望这对您有帮助

这篇关于VBA Excel-如果一列中的单元格包含电子邮件地址,而另一列中的单元格是& quot; SOLD&"., 发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆