简体   繁体   English

Outlook 2013:选择多封电子邮件并使用模板自动回复

[英]Outlook 2013: select multiple emails and autoreply using template

I am trying to get this code to work.我正在尝试使此代码正常工作。

I want to select multiple emails from my inbox and send a auto reply using a template.我想从收件箱中选择多封电子邮件并使用模板发送自动回复。

I am getting a run-time error: Object variable or With Block variable not set.我收到一个运行时错误:未设置对象变量或块变量。

Any help would be appreciated.任何帮助,将不胜感激。 Also I would like to add a msg box telling me how many items were sent.此外,我想添加一个 msg 框,告诉我发送了多少项目。

Option Explicit

Sub ReplywithTemplate()
Dim Item As Outlook.MailItem
Dim oRespond As Outlook.MailItem


For Each Item In ActiveExplorer.Selection

' This sends a response back using a template
Set oRespond = Application.CreateItemFromTemplate("C:\Users\Accounting\AppData\Roaming\Microsoft\Templates\scautoreply.oft")

With oRespond

    .Recipients.Add Item.SenderEmailAddress
    .Subject = Item.Subject

    ' includes the original message as an attachment
    .Attachments.Add Item

    ' use this for testing, change to .send once you have it working as desired
    .Display
End With
On Error Resume Next                                                 
Next
Set oRespond = Nothing

End Sub

I have noticed the following lines of code:我注意到以下几行代码:

 For Each oRespond In ActiveExplorer.Selection

 ' This sends a response back using a template
 Set oRespond = Application.CreateItemFromTemplate("C:\Users\Accounting\AppData\Roaming\Microsoft\Templates\scautoreply.oft")

 With oRespond

You need to use a new variable for creating an auto-reply email from a template because the selected Outlook item is missed (replaced with a newly created one).您需要使用新变量从模板创建自动回复电子邮件,因为所选 Outlook 项目丢失(替换为新创建的项目)。

So, basically you can create an item from a template, add recipients from the selected Outlook item and call the Send method.因此,基本上您可以从模板创建一个项目,从选定的 Outlook 项目添加收件人并调用 Send 方法。 Or you can use the Reply method of the selected item in Outlook, copy the required properties from a template and call the Send method.或者,您可以使用 Outlook 中所选项目的 Reply 方法,从模板复制所需的属性并调用 Send 方法。 It is up to you which way is to choose.选择哪种方式取决于您。

Finally, you may find the Getting Started with VBA in Outlook 2010 article helpful.最后,您可能会发现Outlook 2010 中的 VBA 入门文章很有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM