vba 从 Excel 回复 Outlook 邮件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25238635/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Reply to Outlook mail from Excel
提问by Deva
I am trying to "replytoall" with a given format in the Body.
我正在尝试使用正文中的给定格式“回复所有”。
I use the following code to search for and display the mails.
我使用以下代码来搜索和显示邮件。
Sub Test()
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim olMail As Variant
Dim i As Integer
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
i = 1
For Each olMail In Fldr.Items
If InStr(olMail.Subject, "Application for Privilege Leave - Leave ID - Dev-PL-45252-4") <> 0 Then
olMail.Display
i = i + 1
End If
Next olMail
End Sub
I need to Replyall with the same subject and a prescribed body and signature.
我需要以相同的主题和规定的正文和签名回复所有人。
It is similar to when we open up a mail in Outlook and click on the Reply to All button.
这类似于我们在 Outlook 中打开邮件并单击“全部回复”按钮。
I want it triggered from Excel.
我希望它从 Excel 触发。
回答by Siddharth Rout
Since you are using Early Binding, Change
由于您使用的是早期绑定,因此请更改
Dim olMail As Variant
to
到
Dim olMail As Outlook.MailItem
And then you will be able to access all the properties of the olMail
item. One of which is .ReplyAll
然后您将能够访问该olMail
项目的所有属性。其中之一是.ReplyAll
ScreenShot
截屏
If InStr(olMail.Subject, "Blah Blah") <> 0 Then
olMail.Display
olMail.ReplyAll
DoEvents
'
'~~> Rest of the code
'
i = i + 1
End If
回答by L42
There is a ReplyAllmethod which returns a mail object. See here.
So if you are iterating through some mails, then this should work:
有一个ReplyAll方法返回一个邮件对象。见这里。
因此,如果您正在遍历一些邮件,那么这应该有效:
For Each oMail in Fldr.Items
If InStr(olMail.Subject, "mysubject") <> 0 Then
With oMail.ReplyAll
.Subject = oMail.Subject '~~> this is optional
.Body = "your Body"
'~~> all other stuff you need your mail to have
.Display '~~> change to .Send if it is already ok
End With
End If
Next
Not tested but should be close.
未测试,但应该接近。
回答by bigbryan
Try this one:
试试这个:
olMail.ReplyAll
olMail.ReplyAll.body = bodyMail & vbLF & .body