|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 添加附件()
Application.ScreenUpdating = False
Dim MyName, i, arr
arr = [a1].CurrentRegion
MyName = Dir(ThisWorkbook.Path & "\" & "*.xlsx")
Do While MyName <> ""
For i = 2 To UBound(arr) '隐藏一对多添加功能
If arr(i, 5) = Split(MyName, ".")(0) Then
arr(i, 4) = MyName
Exit For
End If
Next
MyName = Dir
Loop
[a1].CurrentRegion = arr
MsgBox "附件添加完毕!", , "报告!"
End Sub
Sub 发送邮件()
Dim i, arr
Dim OutlookApp As Outlook.Application
Dim OutlookItem As Outlook.MailItem
arr = [a1].CurrentRegion
For i = 2 To UBound(arr)
收件地址 = arr(i, 1): 主题 = arr(i, 2): 内容 = arr(i, 3): 附件 = arr(i, 4)
Set OutlookApp = New Outlook.Application
Set OutlookItem = OutlookApp.CreateItem(olMailItem)
On Error GoTo 错误
With OutlookItem
.To = 收件地址
.Subject = 主题
.Body = 内容
If 附件 <> "" Then
.Attachments.Add ThisWorkbook.Path & "\" & 附件
End If
.Send
End With
Next
发送提示:
MsgBox "发送OK,注意查收!", , "温馨提示!"
Exit Sub
错误:
MsgBox "邮件发送失败!", , "温馨提示!"
Resume 发送提示
End Sub
目标区域你自己修改下 |
|