vba可以操作outlook吗
2个回答
展开全部
以下代码可以实现OUTLOOK发送邮件,B1单元格是写收件人,B2是主题,B3是正文,B4是附件的路径
Sub sendmail()
Dim outlookapp As Outlook.Application
Dim outlookitem As Outlook.MailItem
Set outlookapp = New Outlook.Application
Set outlookitem = Outlook.CreateItem(olMailItem)
Dim receiver As String
Dim subjecttext As String
Dim bodytext As String
Dim attachedobject As String
receiver = [b1].Value
subjecttext = [b2].Value
bodytext = [b3].Value
attachedobject = [b4].Value
On Error GoTo sendmail_error
With outlookitem
.To = receiver
.Subject = subjecttext
.Body = bodytext
If attachedobject <> "" Then
.Attachments.Add attachedobject
End If
.Send
End With
sendmail_exit:
Exit Sub
sendmail_error:
MsgBox Err.Description
Resume sendmail_exit
End Sub
Sub sendmail()
Dim outlookapp As Outlook.Application
Dim outlookitem As Outlook.MailItem
Set outlookapp = New Outlook.Application
Set outlookitem = Outlook.CreateItem(olMailItem)
Dim receiver As String
Dim subjecttext As String
Dim bodytext As String
Dim attachedobject As String
receiver = [b1].Value
subjecttext = [b2].Value
bodytext = [b3].Value
attachedobject = [b4].Value
On Error GoTo sendmail_error
With outlookitem
.To = receiver
.Subject = subjecttext
.Body = bodytext
If attachedobject <> "" Then
.Attachments.Add attachedobject
End If
.Send
End With
sendmail_exit:
Exit Sub
sendmail_error:
MsgBox Err.Description
Resume sendmail_exit
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询