如何使用excel vba 对outlook进行操作?
例如:在excelbook1的sheet1的单元格A1中记录了邮件的标题(ABC),A2中记录了邮件中的一条记录(123),现在想在outlook中检索所有标题与A1中记...
例如:在excel book1的sheet1的单元格A1中记录了邮件的标题(ABC),A2中记录了邮件中的一条记录(123),现在想在outlook中检索所有标题与A1中记载的内容一致的邮件中,包含A2中记录的内容的邮件,如何编写代码?如何访问outlook的命令?
展开
1个回答
展开全部
参考下面的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 = " <p> <b> This </b> is <font color= '#ff000 '> 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
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 = " <p> <b> This </b> is <font color= '#ff000 '> 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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询