|
各位大神,有没有人可以做出来的- Sub SendEmail()
- '要能正确发送并需要对Microseft Outlook进行有效配置
- Dim OutlookApp As New Outlook.Application '要正常运行这句,要将工具/引用中的Microseft Outlook *.0 Object Library(其中*为你Microseft Outlook的版本号)选上
- Dim OutlookItem As MailItem
- Set OutlookApp = New Outlook.Application
-
- Dim sht As Worksheet
- Dim rng As Range
- Set sht = ThisWorkbook.Worksheets(1)
-
- For Each rng In Intersect(sht.Range("a2:a10000"), sht.UsedRange) '开始循环发送电子邮件
-
- Set OutlookItem = OutlookApp.CreateItem(0) '创建objOutlook为Outlook应用程序对象
- Receiver = rng.Value '获取TO的值
- ReceiverCC = rng.Offset(0, 1).Value '获取CC的值
- SubjectText = rng.Offset(0, 2).Value '获取主题的值
- BodyText = rng.Offset(0, 3).Value '获取正文的值
- AttachedObject = rng.Offset(0, 4).Value '获取正文图片的值
-
- '插入图片的格式
- htm = "<html><img src='cid:测试图片.png' height=500 width=700><br/>" & _
- "<b> ★ <b/>" & _
- "<a href = 'https://www.baidu.com/'><font size='5'>MyJob</font></a>" & _
- "<b> ★ <b/>" & _
- "<a href = 'https://www.baidu.com/'><font size='5'>MyPlan</font></a>" & _
- "<b> ★ <b/>" & _
- "<a href = 'https://www.baidu.com/'><font size='5'>Skills</font></a>" & _
- "<b> ★ <b/>" & _
- "<a href = 'https://www.baidu.com/'><font size='5'>CV</font></a>" & _
- "<b> ★<b/>"
- With OutlookItem
- OutlookItem.SentOnBehalfOfName = "XXXXXXXXXX" '发送人地址
- .To = Receiver '设置TO地址
- .CC = ReceiverCC '设置CC地址
- .Subject = SubjectText '设置主题地址
- .HTMLBody = BodyText & htm '设置邮件内容
- If AttachedObject <> "" Then
- .Attachments.Add ThisWorkbook.Path & "" & AttachedObject
- End If
- '.Display '预览邮件
- .Send '发送邮件
- End With
- Set OutlookItem = Nothing '销毁OutlookItem对象
- Next
- MsgBox ("Email sent successfully!")
- End Sub
复制代码
|
|