在VBA中实现通过Outlook发送邮件

1.添加引用Microsoft Outlook 11.0 Object Library。(这里用的是Microsoft Outlook 2003)
 
2.定义发送邮件过程。
Public Sub SendEmail(Receiver As String, SubjectText As String, BodyText As String, AttachedObject As String)
    Dim OutlookApp As Outlook.Application
    Dim OutlookItem As Outlook.MailItem
   
    Set OutlookApp = New Outlook.Application
    Set OutlookItem = OutlookApp.CreateItem(olMailItem)
   
On Error GoTo SendEmail_Error
    With OutlookItem
        .To = Receiver '收件人地址
        .Subject = SubjectText '邮件主题
        .Body = BodyText '邮件内容
        .Attachments.Add AttachedObject '粘贴附件
        .Send '发送邮件
    End With
SendEmail_Exit:
    Exit Sub
  
SendEmail_Error:
    MsgBox Err.Description
    Resume SendEmail_Exit
End Sub
 
3.调用发送邮件过程。
    SendEmail "jmfrd@126.com", "需求分析", "现有一项目需开发,详情请见附件。", "E:/需求分析.doc"
 
4.在Outlook中添加新电子邮件帐户。
posted @ 2009-05-08 14:07  Nina  阅读(1505)  评论(0编辑  收藏  举报