excel办公技巧怎样发邮件(Excel VBA 一键发送电子邮件(Email))
- 办公技巧
- 2023-07-12 06:34:35
- 0
工作中经常需要发送邮件,每次都需要登录邮箱很是麻烦,有没有一种简单的方式发送邮件呢,答案当然是有的啦,下面是笔者用Excel VBA 的方法进行邮件发送,简直不要太方便。
首先,新建或打开一个已有的Excel 文件,这里新建一个Excel文件,名称为datafile.xlsx,在sheet1工作表中编辑内容如下:
第二,打开VBA编辑器,插入一个模块,输入如下代码:
Sub SendEmail()
'定义变量
Dim receiver As String
Dim subjecttext As String
Dim bodytext As String
Dim attachedobject1 As String
Dim attachedobject2 As String
Dim attachedobject3 As String
Dim attachedobject4 As String
Dim OutlookApp As Outlook.Application
Dim OutlookItem As Outlook.mailItem
Dim sh As Worksheet
'给变量赋值
Set sh = Sheets(1)
Set OutlookApp = New Outlook.Application
Set OutlookItem = OutlookApp.CreateItem(olMailItem)
receiver = sh.[B1].Value
subjecttext = sh.[B2].Value
bodytext = sh.[B3].Value
attachedobject1 = sh.[B4].Value
attachedobject2 = sh.[B5].Value
attachedobject3 = sh.[B6].Value
attachedobject4 = sh.[B7].Value
On Error GoTo SendEmail_Error
With OutlookItem
.To = receiver
.Subject = subjecttext
.Body = bodytext
If attachedobject1 <> "" Then
.Attachments.Add attachedobject1
.Attachments.Add attachedobject2
.Attachments.Add attachedobject3
.Attachments.Add attachedobject4
End If
.send
MsgBox "Sent sucessfully"
End With
SendEmail_Exit:
Exit Sub
SendEmail_Error:
MsgBox Err.Description
Resume SendEmail_Exit
End Sub
第三,点击运行,一键发送:
打开邮箱查收邮件:
只需三步,即可一键发送邮件。
友友,还不赶快行动起来试试吧。
记得关注、点赞、评论、收藏哟!
本文由 京廊文化根据互联网搜索查询后整理发布,旨在分享有价值的内容,本站为非营利性网站,不参与任何商业性质行为,文章如有侵权请联系删除,部分文章如未署名作者来源请联系我们及时备注,感谢您的支持。
本文链接: /bangong/8814.html