如何使用excel vba,对outlook进行操作?

2020-10-03 科技 79阅读
参考下面的VBA代码

Sub Send_Email()
Dim i As Integer
Dim MyOutlookApp As Outlook.Application
Dim MyFolder As Outlook.MAPIFolder
Dim MyNewMail As Outlook.MailItem
Dim MyAttachments As Outlook.Attachments '附件

Set MyOutlookApp = New Outlook.Application

Set MyFolder = MyOutlookApp.GetNamespace( "MAPI ").GetDefaultFolder(olFolderInbox).Folders( "我的邮件文件夹 ")

Set MyNewMail = MyOutlookApp.CreateItem(olMailItem)
With MyNewMail
.To = "YourFridentMail@sina.com " '目标邮件地址
.Cc="aaa@qq.com"
.Subject = "test " '标题
.HTMLBody = "

This </b> is red </font> </p> "
.AlternateRecipientAllowed = True '此邮件可转发
.AutoForwarded = True '此邮件允许自动转发
.DeleteAfterSubmit = False '发送后保留副本
'发送之后移动到指定文件夹
.SaveSentMessageFolder = MyOutlookApp.GetNamespace( "MAPI ").GetDefaultFolder(olFolderInbox).Folders( "备份文件夹 ")
.ReadReceiptRequested = True '要求收件人回执
'SaveSentMessageFolder
End With
'附件
Set MyAttachments = MyNewMail.Attachments
MyAttachments.Add "c:\win\abc.txt ", olByValue
MyNewMail.Save '保存
MyNewMail.Send '发送

MyFolder.Display '显示office outlook
End Sub

声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com