我正在尝试将我的电子邮件填充到字段中,并将电子邮件地址存储为单元格AF中的值。
AF8 = info@email.com
AF9 = help@email.com
AF10 = hello@email.com
我正在尝试使用选择范围,因为每行中的每个AF单元格都包含不同的电子邮件地址,因此当用户选择了一行时,应该从AF获取该行的相应单元格值。
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = Range("CA8").Column Then
Dim Email_Subject, Email_Send_From, Email_Send_To, _
Email_Cc, Email_Bcc, Email_Body As String
Dim Mail_Object, Mail_Single As Variant
Email_Subject = "New Supplier Set-Up Confirmation"
Email_Send_From = "purchasing@hewden.co.uk"
Email_Send_To = Range("AF8").Select
Email_Cc = "databison@gmail.com"
Email_Bcc = "databison@gmail.com"
Email_Body = "Congratulations!!!! You have successfully sent an e-mail using VBA !!!!"
On Error GoTo debugs
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
.Subject = Email_Subject
.To = Range("AF8").Select
.cc = Email_Cc
.BCC = Email_Bcc
.Body = Email_Body
.send
End With
debugs:
If Err.Description <> "" Then MsgBox Err.Description
End If
End Sub
然而,当我尝试这段代码时,它会出现错误, &#34; outlook无法识别一个或多个名称&#34;
答案 0 :(得分:0)
。想要一个字符串
http://msdn.microsoft.com/en-us/library/office/ff860378%28v=office.15%29.aspx
“...设置以分号分隔的字符串列表......”
Email_Send_To = Range("AF8").Value
一旦Email_Send_To是一个字符串值,那么
.To = Email_Send_To