在活动电子邮件的主题中查找和替换宏

时间:2015-07-05 13:11:50

标签: vba outlook-vba

我有一个MIS,可以为工作说明生成自动电子邮件。但是我操纵了水晶报告以作出订单确认,并想用"Work Instruction '1234' 'date' etc"

替换"Order Acknowledgement '1234' 'date' etc".的SUBJECT中的单词。

我想点击我添加到'撰写电子邮件'屏幕的宏按钮来执行此操作

这是我尝试过的,目前无效。

Sub OrderAck()
    Dim OrdAck As String
    Dim NewMail As Outlook.MailItem

    Set NewMail = Application.ActiveInspector.CurrentItem

    OrdAck = Replace(NewMail.Subject, "Works Instruction", "Order Acknowledgement")

    NewMail.Subject = OrdAck
    NewMail.Subject = Display

End Sub

1 个答案:

答案 0 :(得分:0)

要编辑主题行,请尝试以下

Option Explicit
Sub OrderAck()
    Dim olItem As Object
    Dim OrdAck As String
    Dim sNew As String
    Dim NewMail As Outlook.Application

    Set NewMail = Application
    Set olItem = NewMail.ActiveExplorer.Selection.Item(1)

    OrdAck = Replace(olItem.Subject, "Works Instruction", "Order Acknowledgement")

    sNew = OrdAck
    olItem.Subject = sNew
    olItem.Save
End Sub