我想改善我的代碼我從以前的帖子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