文章源自略懂百科-http://wswcn.cn/113135.html
工作中经常需要发送邮件,每次都需要登录邮箱很是麻烦,有没有一种简单的方式发送邮件呢,答案当然是有的啦,下面是笔者用Excel VBA 的方法进行邮件发送,简直不要太方便。文章源自略懂百科-http://wswcn.cn/113135.html
首先,新建或打开一个已有的Excel 文件,这里新建一个Excel文件,名称为datafile.xlsx,在sheet1工作表中编辑内容如下:文章源自略懂百科-http://wswcn.cn/113135.html
第二,打开VBA编辑器,插入一个模块,输入如下代码:文章源自略懂百科-http://wswcn.cn/113135.html
Sub SendEmail()文章源自略懂百科-http://wswcn.cn/113135.html
定义变量文章源自略懂百科-http://wswcn.cn/113135.html
Dim receiver As String文章源自略懂百科-http://wswcn.cn/113135.html
Dim subjecttext As String文章源自略懂百科-http://wswcn.cn/113135.html
Dim bodytext As String文章源自略懂百科-http://wswcn.cn/113135.html
Dim attachedobject1 As String文章源自略懂百科-http://wswcn.cn/113135.html
Dim attachedobject2 As String文章源自略懂百科-http://wswcn.cn/113135.html
Dim attachedobject3 As String文章源自略懂百科-http://wswcn.cn/113135.html
Dim attachedobject4 As String文章源自略懂百科-http://wswcn.cn/113135.html
Dim OutlookApp As Outlook.Application文章源自略懂百科-http://wswcn.cn/113135.html
Dim OutlookItem As Outlook.mailItem文章源自略懂百科-http://wswcn.cn/113135.html
Dim sh As Worksheet文章源自略懂百科-http://wswcn.cn/113135.html
给变量赋值文章源自略懂百科-http://wswcn.cn/113135.html
Set sh = Sheets(1)文章源自略懂百科-http://wswcn.cn/113135.html
Set OutlookApp = New Outlook.Application文章源自略懂百科-http://wswcn.cn/113135.html
Set OutlookItem = OutlookApp.CreateItem(olMailItem)文章源自略懂百科-http://wswcn.cn/113135.html
receiver = sh.[B1].Value文章源自略懂百科-http://wswcn.cn/113135.html
subjecttext = sh.[B2].Value文章源自略懂百科-http://wswcn.cn/113135.html
bodytext = sh.[B3].Value文章源自略懂百科-http://wswcn.cn/113135.html
attachedobject1 = sh.[B4].Value文章源自略懂百科-http://wswcn.cn/113135.html
attachedobject2 = sh.[B5].Value文章源自略懂百科-http://wswcn.cn/113135.html
attachedobject3 = sh.[B6].Value文章源自略懂百科-http://wswcn.cn/113135.html
attachedobject4 = sh.[B7].Value文章源自略懂百科-http://wswcn.cn/113135.html
On Error GoTo SendEmail_Error文章源自略懂百科-http://wswcn.cn/113135.html
With OutlookItem文章源自略懂百科-http://wswcn.cn/113135.html
.To = receiver文章源自略懂百科-http://wswcn.cn/113135.html
.Subject = subjecttext文章源自略懂百科-http://wswcn.cn/113135.html
.Body = bodytext文章源自略懂百科-http://wswcn.cn/113135.html
If attachedobject1 <> "" Then文章源自略懂百科-http://wswcn.cn/113135.html
.Attachments.Add attachedobject1文章源自略懂百科-http://wswcn.cn/113135.html
.Attachments.Add attachedobject2文章源自略懂百科-http://wswcn.cn/113135.html
.Attachments.Add attachedobject3文章源自略懂百科-http://wswcn.cn/113135.html
.Attachments.Add attachedobject4文章源自略懂百科-http://wswcn.cn/113135.html
End If文章源自略懂百科-http://wswcn.cn/113135.html
.send文章源自略懂百科-http://wswcn.cn/113135.html
MsgBox "Sent sucessfully"文章源自略懂百科-http://wswcn.cn/113135.html
End With文章源自略懂百科-http://wswcn.cn/113135.html
SendEmail_Exit:文章源自略懂百科-http://wswcn.cn/113135.html
Exit Sub文章源自略懂百科-http://wswcn.cn/113135.html
SendEmail_Error:文章源自略懂百科-http://wswcn.cn/113135.html
MsgBox Err.Description文章源自略懂百科-http://wswcn.cn/113135.html
Resume SendEmail_Exit文章源自略懂百科-http://wswcn.cn/113135.html
End Sub文章源自略懂百科-http://wswcn.cn/113135.html
第三,点击运行,一键发送:文章源自略懂百科-http://wswcn.cn/113135.html
打开邮箱查收邮件:文章源自略懂百科-http://wswcn.cn/113135.html
只需三步,即可一键发送邮件。文章源自略懂百科-http://wswcn.cn/113135.html
友友,还不赶快行动起来试试吧。文章源自略懂百科-http://wswcn.cn/113135.html
记得关注、点赞、评论、收藏哟!文章源自略懂百科-http://wswcn.cn/113135.html
文章源自略懂百科-http://wswcn.cn/113135.html
评论