|
- Sub sendemail()
- 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("Sheet1")
- i = 2
- Do While .Cells(i, 2) <> ""
- Set myitem = myOlApp.CreateItem(0)
- Set atts = myitem.Attachments
- myitem.To = .Cells(i, 2) '收件人E-mail
- myitem.cc = .Cells(i, 3) 'CC
- myitem.Subject = .Cells(i, 4) '标题
- myitem.Body = .Cells(i, 1) & ",你好!" & vbNewLine & vbNewLine & vbNewLine & .Cells(i, 5) '正文
- myfile = Dir(ThisWorkbook.Path & "\*" & .Cells(i, 1) & "*.*")
- Do Until myfile = ""
- myitem.Attachments.Add ThisWorkbook.Path & "" & myfile, 1
- myfile = Dir
- Loop
- myitem.display '预览,如果想直接发送,把.display改为.send
- i = i + 1
- strg = ""
- Loop
- End With
- Set myitem = Nothing
- End Sub
复制代码 |
评分
-
4
查看全部评分
-
|