我有一个Excel文档,可以用作投资银行的客户计划人员。该文档中有200多个帐户,每个帐户都有自己的一行。有一栏显示每个帐户的日期,指示销售代表下次需要跟进该帐户的日期。我正在尝试编写VBA代码,以在工作表中搜索后续日期= DATE(即今天)的任何帐户,然后发送列出相关帐户的电子邮件。我具有单个帐户的功能代码(如下),但是我不确定如何使代码搜索整个工作表,也不确定如何使电子邮件文本动态显示所有关联的帐户。请注意,我在编码方面没有扎实的背景-我将根据研究内容将其拼凑在一起,因此我需要尽可能清晰,无术语的答案。预先感谢您的帮助!
Sub Send_Emails()
If Worksheets("Master").Range("H10").Value = Date Then
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
Dim Flds As Variant
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Update
End With
strbody = "The following account(s) need follow up today. If you've already made contact with this account, please make sure to indicate the date in the Account Planner" & vbNewLine & vbNewLine & _
Worksheets("Master").Range("A10").Value
With iMsg
Set .Configuration = iConf
.To = "email"
.CC = ""
.BCC = ""
.From = """EBB Alert"" <ebb.alert@gmail.com>"
.Subject = "Account Planner Reminder"
.TextBody = strbody
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
Else
Exit Sub
End If
End Sub