[英]Excel 2013 VBA multiple email addresses to Outlook
I am coding in Excel 2013. I've got a table of client data that will increase and decrease in number over time depending my active veteran caseload: 我正在用Excel 2013进行编码。我有一个客户数据表,该数据将随着我的资深退伍军人案件数量而随着时间增加和减少 :
Column A - Last Name A栏-姓
Column B - First Name B栏-名
Column C - Email Address C栏-电子邮件地址
Column D - etc... D列-等等...
I need the code to reference column C and place all the emails therein in the BCC of a single Outlook email. 我需要代码来引用C列,并将其中的所有电子邮件放在单个Outlook电子邮件的密件抄送中。 The code I have created (through my study) allows for only hard-coded email addresses to the TO, CC or BCC fields of Outlook--with a semicolon between multiple entries.
我创建的代码(通过我的研究)仅允许将硬编码的电子邮件地址发送到Outlook的TO,CC或BCC字段-在多个条目之间使用分号。 My issue is that the number of email addresses will vary depending on the number of records in the spreadsheet so hard-coding them is useless.
我的问题是,电子邮件地址的数量将取决于电子表格中记录的数量,因此对它们进行硬编码是没有用的。 The code below has all the functionality I require with the exception of the email problem.
下面的代码具有我需要的所有功能,但电子邮件问题除外。
Sub SendBasicEmail()
Dim olApp As Outlook.Application
Dim olEmail As Outlook.MailItem
Set olApp = New Outlook.Application
Set olEmail = olApp.CreateItem(olMailItem)
With olEmail
.BodyFormat = olFormatHTML
.Display
.HTMLBody = "<h3>Testing</h3><br>" & "<br>" & .HTMLBody
.Attachments.Add "xxx/test.pdf"
.To = ""
.BCC = ""
.Subject = "Test Message"
'.Send
End With
End Sub
The code will loop through the contents of sheet 1 (just change to sheet("whateveryoucalledyoursheet")) and keep the cell row. 该代码将遍历工作表1的内容(只需更改为sheet(“ whateveryouyouyoursheet”)),并保留单元格行。
Sub SendBasicEmail()
dim ws as worksheet, y
Dim olApp As Outlook.Application
Dim olEmail As Outlook.MailItem
set ws = sheets(1)
for each y in ws.range("A1:A" & ws.range("A1").SpecialCells(xlCellTypeLastCell).row)
Set olApp = New Outlook.Application
Set olEmail = olApp.CreateItem(olMailItem)
With olEmail
.BodyFormat = olFormatHTML
.Display
.HTMLBody = "<h3>Testing</h3><br>" & "<br>" & .HTMLBody
.Attachments.Add "xxx/test.pdf"
.To = ws.range("A" & y.row)
.BCC = ws.range("C" & y.row)
.Subject = "Test Message"
' use display to check the email out before you send
.display
'.Send
End With
next y
end sub
I'd just loop over the column and make string holding the addresses separated by semi-colons. 我只是循环遍历该列,并创建包含用分号分隔的地址的字符串。
Sub SendBasicEmail()
Dim olApp As Outlook.Application
Dim olEmail As Outlook.MailItem
Set olApp = New Outlook.Application
Set olEmail = olApp.CreateItem(olMailItem)
'set your range as needed, i chose one named "recipients"
bc_r = ""
For each cl in range("recipients")
bc_r = bc_r & "; " & cl.Value
Next cl
With olEmail
.BodyFormat = olFormatHTML
.Display
.HTMLBody = "<h3>Testing</h3><br>" & "<br>" & .HTMLBody
.Attachments.Add "xxx/test.pdf"
.To = ""
.BCC = bc_r
.Subject = "Test Message"
'.Send
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.