我想改善我的代码我从以前的帖子Predetermine the cells with the data to send emails把一些碳复制(CC)的行代码。我想弄清楚的是,有些公司可能是我的CC,这取决于我想发送的电子邮件类型。如何提高这个VBA代码添加碳复制到它
例如:我创建了2个CC电子邮件列表,我可能想发送电子邮件。
在公司名称前面我串连所有列表中的邮件只有一个细胞。
我怎样才能把这个代码放入我可以选择公司名称的公司名称以及该公司的所有电子邮件都转到CC列表中?
再次感谢你们帮助你们给我的所有帮助。
我将代码从以前的帖子复制只是为了更容易阅读:
Sub SendEMail()
'update by Extendoffice 20160506
Dim xEmail As String
Dim xSubj As String
Dim xMsg As String
Dim xURL As String
Dim i As Integer
Dim k As Double
Dim xCell As Range
Dim xRg As Range
Dim xTxt As String
On Error Resume Next
xTxt = ActiveWindow.RangeSelection.Address
Set xRg = Range("A2:C6")
If xRg Is Nothing Then Exit Sub
For i = 1 To xRg.Rows.Count
' Get the email address
xEmail = xRg.Cells(i, 2)
' Message subject
xSubj = "Your Registration Code"
' Compose the message
xMsg = ""
xMsg = xMsg & "Dear " & xRg.Cells(i, 1) & "," & vbCrLf & vbCrLf
xMsg = xMsg & " This is your Registration Code "
xMsg = xMsg & xRg.Cells(i, 3).Text & "." & vbCrLf & vbCrLf
xMsg = xMsg & " please try it, and glad to get your feedback! " & vbCrLf
xMsg = xMsg & "Skyyang"
' Replace spaces with %20 (hex)
xSubj = Application.WorksheetFunction.Substitute(xSubj, " ", "%20")
xMsg = Application.WorksheetFunction.Substitute(xMsg, " ", "%20")
' Replace carriage returns with %0D%0A (hex)
xMsg = Application.WorksheetFunction.Substitute(xMsg, vbCrLf, "%0D%0A")
' Create the URL
xURL = "mailto:" & xEmail & "?subject=" & xSubj & "&body=" & xMsg
' Execute the URL (start the email client)
ShellExecute 0&, vbNullString, xURL, vbNullString, vbNullString, vbNormalFocus
' Wait two seconds before sending keystrokes
Application.DisplayKeys "%s"
Next
End Sub
您希望数据集中的一个字段标识哪个公司与您要发送的电子邮件相关联(如果这是一个公司,可能会从关联的电子邮件域派生出来)永久的方式来找到公司)。然后,在运行宏时,您可以根据您定义的公司字段查找CC的列表,并将其添加到xURL字符串中,例如“&cc =”&xCCs(我不知道您需要的URL的实际格式这只是一个例子)。 – Wedge