如何在替换名称值时使用默认模板进行回复


0

我想知道这是否可行?我收到的电子邮件必须通过以下消息回复

Hello NAME,

Your request has been completed.

Thank you.

有没有办法让我只需点击一下按钮就能自动完成这个过程?还有一种方法让我用发件人名称填充NAME吗?当前发件人名称出现在“发件人”字段中,如下所示LastName,FirstName。我想将消息的NAME变量替换为FirstName值。

我想知道这是否可能与Outlook 2003?

任何帮助将不胜感激。

谢谢。

Answers:


0

使用您的文本保存模板文件。在代码中,它保存到C驱动器并命名为NamePlaceholder.oft。根据需要改变。

在运行代码之前打开请求。

Sub CreateReplyFromTemplate()

Dim currItem  As Outlook.mailItem
Dim currItemReply  As Outlook.mailItem
Dim myItem As Outlook.mailItem

Dim commaPositionRight As Long
Dim Firstname As String

Set currItem = ActiveInspector.currentItem
Set currItemReply = currItem.Reply
Set myItem = Application.CreateItemFromTemplate("C:\NamePlaceholder.oft")

myItem.To = currItemReply.To
commaPositionRight = InStrRev(myItem.To, ",")
Firstname = Right(myItem.To, commaPositionRight)

myItem.Subject = currItem.Subject

' if "RE:" or "FW:" on the request,
'  and the client replies there would be an extra "RE:" or "FW:"
If InStr(myItem.Subject, "RE: ") = 1 Or InStr(myItem.Subject, "FW: ") = 1 Then
    myItem.Subject = Right(myItem.Subject, Len(myItem.Subject) - 4)
End If

myItem.HTMLBody = myItem.HTMLBody & currItemReply.HTMLBody
myItem.HTMLBody = Replace(myItem.HTMLBody, "NAME", Firstname)

currItemReply.Close olDiscard
currItem.Close olDiscard

myItem.Display

Set currItemReply = Nothing
Set myItem = Nothing
Set currItem = Nothing

End Sub

如果您不熟悉VBA,请看这里 http://www.slipstick.com/developer/how-to-use-outlooks-vba-editor/

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.