首页 文章

回复时,Outlook VBA/macro 至 delete/move 原始电子邮件

提问于
浏览
-1

在我的工作中,我们有一个票务系统,可以自动向我们发送标题为New Ticket Created: T20120803.0078的票证,并在其中生成号码。然后,我们通过电子邮件回复所有人,说我们正在处理故障单。回复看起来像是RE: New Ticket Created: T20120803.0072

我的 Outlook 设置为将所有票证转发到一个名为Tickets的文件夹中。我试图弄清楚如何能够运行脚本或宏,以便在回复电子邮件时也将回复和原始邮件发送到另一个名为InProgress的文件夹。

我上过编程学校,但是没有很多时间去弄清楚这个。任何帮助将不胜感激。我认为这很容易。从主题行中获取号码并与其他门票进行比较。如果票证号码匹配,请移动它们。

1 回答

  • 2

    don't have a lot of time to figure this one out.

    通常,在这种情况下,我们不是为人员构建代码,而是帮助他们在苦苦挣扎的地方构建经过调整或完善的代码。

    就是说,我对您的问题很感兴趣,想学习自己,所以我为您准备了一些东西。如果尚未完全满足您的需要,这应该为您提供一个很好的开始。

    更新:

    您甚至不需要第一部分的 VBA。您可以设置一个规则,以将主题行中带有"RE: New Ticket Created"的所有已发送邮件移至In Progress文件夹。因此,您甚至不需要以下代码中的整个第一个IfF Then End If块。 (出于目的,我已将其留作参考)。

    所有假设均基于您提供的设置。

    将代码放在 Outlook VBE 中的 ThisOutlookSession 对象的 Application_ItemSend 事件中。

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    
    Dim olNameSpace As Outlook.NameSpace
    Set olNameSpace = GetNamespace("MAPI")
    
    Dim olDestFolder As Outlook.Folder
    Set olDestFolder = olNameSpace.Folders("myMailbox@myCompany.com").Folders("In Progress")
    
    If TypeName(Item) = "MailItem" Then 'if it's a mail item being sent
    
        Dim olMailCopy As Outlook.MailItem
        Set olMailCopy = Item.Copy 'copy the item so we can move it and still have it send
    
        If InStr(1, olMailCopy.Subject, "New Ticket Created") > 0 Then '
    
            olMailCopy.Move olDestFolder ' move copy of mail to folder
    
            Dim strTicket As String
            strTicket = Mid(olMailCopy.Subject, InStrRev(olMailCopy.Subject, ": ") + 2) 'just grab ticket id
    
        End If
    
    End If
    
    Dim olLookUpFolder As Outlook.Folder
    Set olLookUpFolder = olNameSpace.Folders("myMailbox@myCompany.com").Folders("Tickets")
    
    Dim olMail As Outlook.MailItem
    
    For Each olMail In olLookUpFolder.Items 'loop through Tickets folder to find original mail
    
        If InStr(1, olMail.Subject, strTicket) > 0 Then 'look for unique ticket Id
    
            olMail.Move olDestFolder ' move to InProgress folder
    
            Exit For
    
        End If
    
    Next
    
    End Sub
    

相关问题