|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
若要求第三个收件人“liweifang”(部门主管?)只需收到上一行加本行两个附件,则如下:
- Sub displayemail2()
- Dim myOlApp As Object
- Dim myitem As Object
- Dim i As Integer, j As Integer
- Dim strg As String
- Dim atts As Object
- Dim mycc As Object
- Dim myfile As String
- Set myOlApp = CreateObject("Outlook.Application")
-
- With Sheets("发送名单")
- i = 2
- Do While .Cells(i, 2) <> ""
- Set myitem = myOlApp.CreateItem(0)
- Set atts = myitem.attachments
- myitem.To = .Cells(i, 3) '收件人E-mail
- myitem.cc = .Cells(i, 4) 'Cc
- myitem.Subject = .Cells(i, 5) '标题
- myitem.Body = "Dear:" & vbNewLine & "#REF!单元格数据为空!" '正文
- myfile = Dir(ThisWorkbook.Path & "\*" & .Cells(i, 1) & "*.*")
- 'Do Until myfile = ""
- 'myitem.attachments.Add ThisWorkbook.Path & "" & myfile, 1 '上传附件
- 'myfile = Dir
- If .Cells(i, 7) <> "" Then
- myitem.attachments.Add ThisWorkbook.Path & "" & Dir(ThisWorkbook.Path & "\*" & .Cells(i - 1, 1) & "*.*"), 1
- myitem.attachments.Add ThisWorkbook.Path & "" & Dir(ThisWorkbook.Path & "\*" & .Cells(i, 1) & "*.*"), 1
- myfile = Dir
- Else
- myitem.attachments.Add ThisWorkbook.Path & "" & myfile, 1 '上传附件
- myfile = Dir
- End If
- 'Loop
- myitem.display '预览,如果想直接发送,把.display改为.send
- i = i + 1
- strg = ""
- Loop
- End With
- Set myitem = Nothing
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|