将Outlook电子邮件发送到使用Excel的收件人列表中
问题描述:
我想将选定数据通过电子邮件发送到Excel vba收件人列表。将Outlook电子邮件发送到使用Excel的收件人列表中
例子:
列A小时
列B房价
C列总
列d的电子邮件地址
我们有数以百计的人用自己的支付细节的名单每周要发出基础。我们将信息从Excel文件复制并粘贴到Outlook电子邮件中。
有没有办法用Excel VBA发送电子邮件?
答
这应该有助于让您开始正确的方向。
Sub SendEmail()
Dim OutApp As Object, OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = 'Your Contact List
.CC = ""
.BCC = ""
.Subject = "Your Subject Name"
.HTMLBody = 'The email body
.Display
End With
End Sub
答
In column A : Names of the people
In column B : E-mail addresses
In column C:Z : Filenames like this C:\Data\Book2.xls (don't have to be Excel files)
通过“工作表Sheet1”每一行和宏将循环如果在C列在B列 和文件名(S)一个E-mail地址位:Z它会创建一个邮件与此信息并发送它。
Sub Send_Files()
'Working in Excel 2000-2016
'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
Dim OutApp As Object
Dim OutMail As Object
Dim sh As Worksheet
Dim cell As Range
Dim FileCell As Range
Dim rng As Range
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set sh = Sheets("Sheet1")
Set OutApp = CreateObject("Outlook.Application")
For Each cell In sh.Columns("B").Cells.SpecialCells(xlCellTypeConstants)
'Enter the path/file names in the C:Z column in each row
Set rng = sh.Cells(cell.Row, 1).Range("C1:Z1")
If cell.Value Like "?*@?*.?*" And _
Application.WorksheetFunction.CountA(rng) > 0 Then
Set OutMail = OutApp.CreateItem(0)
With OutMail
.to = cell.Value
.Subject = "Testfile"
.Body = "Hi " & cell.Offset(0, -1).Value
For Each FileCell In rng.SpecialCells(xlCellTypeConstants)
If Trim(FileCell) <> "" Then
If Dir(FileCell.Value) <> "" Then
.Attachments.Add FileCell.Value
End If
End If
Next FileCell
.Send 'Or use .Display
End With
Set OutMail = Nothing
End If
Next cell
Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
您好,欢迎堆栈溢出!这是一个非常广泛的问题。你已经尝试了什么? – Chilangosta