|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 onlycxb 于 2014-10-10 06:14 编辑
去采摘一天,才回来.简单写了个代码,请测试!
- Sub SendMail()
- Dim Conn As ADODB.Connection, rst As ADODB.Recordset, MyData As String, StrSql As String, arr
- Dim olApp As Object, oitem As Object, i%
- MyData = "db1.mdb"
- Set Conn = New ADODB.Connection
- Set rst = New ADODB.Recordset
- Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & ThisWorkbook.Path & "" & MyData
- If Conn.State = adStateOpen Then
- StrSql = "Select * From [CallLog] "
- rst.Open StrSql, Conn, adOpenStatic
- End If
- arr = Application.WorksheetFunction.Transpose(rst.GetRows)
- Set olApp = CreateObject("outlook.application")
- For i = 1 To UBound(arr, 1)
- If InStr(arr(i, 8), "返回按键") Then
- Set oitem = olApp.CreateItem(olMailItem)
- With oitem
- .Subject = ""
- .To = "admin@ test.com"
- .Body = arr(i, 2) & arr(i, 8)
- .Send
- End With
- Set oitem = Nothing
- End If
- Next i
- Set olApp = Nothing
- End Sub
- '以上代码假定数据库db1.mdb与代码文件在同一个文件夹内,可根据需要灵活修改.DongYu(Q:470208739)
复制代码 |
评分
-
1
查看全部评分
-
|