2010-12-17 62 views
1

如何在主題中包含特定單詞的情況下編寫替換主題的VBA方法。該代碼會在電子郵件正文中找到某個關鍵字(與主題關鍵字不同)。然後,它會在文本正文中的關鍵詞之後用13個charactar替換主題行。更改展望主題行

以下內容已經找到,但沒有提及如何在電子郵件正文中找到任何內容。我沒有得到MAPI參考。

任何幫助將真正理解 預先感謝您的任何援助 裏克

Sub RewriteSubject(MyMail As MailItem) 
    Dim mailId As String 
    Dim outlookNS As Outlook.NameSpace 
    Dim myMailItem As Outlook.MailItem 

    mailId = MyMail.EntryID 

    Set outlookNS = Application.GetNamespace("MAPI") 
    Set myMailItem = outlookNS .GetItemFromID(mailId) 

    ' Do any detection here 
    mailItem.Subject = "Dept - " & mailItem.Subject 
    myMailItem.Save 

    Set mailItem = Nothing 
    Set outlookNS = Nothing 
End Sub 

回答

1

如果是針對所有新郵件,那麼你可以使用下面的

私人小組實現Application_ItemSend(BYVAL項目作爲對象,取消爲布爾)

Dim v As Variant 
    For Each v In Array("first", "second") 
     If InStr(1, Item.Subject, v, vbTextCompare) <> 0 Then 
      SearchForAttachWords = True 
     End If 
    Next 

    If SearchForAttachWords = True Then 
     Item.Subject = "Whatever subject you want" 
    End If  

End Sub 

希望這會有所幫助。