office交流網(wǎng)--QQ交流群號(hào)及微信交流群

Access培訓(xùn)群:792054000         Excel免費(fèi)交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

微信交流群(請(qǐng)用微信掃碼)

        

Access或Excel VBA使用CDO批量發(fā)送郵件

2019-07-15 16:06:00
zstmtony
原創(chuàng)
5145



ACCESS及VBA可以通過微軟的CDO來發(fā)送郵件, (不需要安裝其他控件和引用DLL庫(kù)文件)這樣使用非常方便,比調(diào)用Outlook的MAPI更加方便
 

Dim objEmail As Object
Dim strName As String

 

Private Sub Form_Load()
    strName = "http://schemas.microsoft.com/cdo/configuration/"
    Set objEmail = CreateObject("CDO.Message")
End Sub

Private Sub Command1_Click()
    Me.Caption = "正在發(fā)送..."
    Command1.Enabled = False
    objEmail.From = "tmtony@21cn.com"
    objEmail.To = "test@qq.com"
    objEmail.Subject = "郵件發(fā)送測(cè)試(Access交流網(wǎng))"
    objEmail.Textbody = "郵件發(fā)送測(cè)試內(nèi)容(Office中國(guó)交流網(wǎng))"
    objEmail.Configuration.Fields.Item(strName & "sendusing") = 2
    objEmail.Configuration.Fields.Item(strName & "smtpserver") = "smtp.21cn.com"
    objEmail.Configuration.Fields.Item(strName & "smtpserverport") = 25
    objEmail.Configuration.Fields.Item(strName & "smtpauthenticate") = 1
    objEmail.Configuration.Fields.Item(strName & "sendusername") = "tmtony@21cn.com"
    objEmail.Configuration.Fields.Item(strName & "sendpassword") = "XXXXXXXXXX"
    objEmail.Configuration.Fields.Update
    objEmail.Send
    Command1.Enabled = True
    Me.Caption = "Send OK!"
    MsgBox "郵件發(fā)送成功,謝謝,歡迎您使用Access交流網(wǎng)的代碼"
    End
End Sub
分享
文章分類
聯(lián)系我們
聯(lián)系人: 王先生
Email: 18449932@qq.com
QQ: 18449932
微博: officecn01
移動(dòng)訪問