开发者

Change outlook subject line

开发者 https://www.devze.com 2023-01-31 17:16 出处:网络
How do I write a VBA method that replaces the subject if there is a specific word in the subject. This code would find a certain key word (different than the subject key word) in the body of the email

How do I write a VBA method that replaces the subject if there is a specific word in the subject. This code would find a certain key word (different than the subject key word) in the body of the email. It would then replace the subject line with 13 charactars after the key word found in the body of the text.

The below was already found but doesn't mention how to find anything in the body of the email. And I don't get the MAPI reference.

Any help would truly be appreciated Thank You in advance for any assistance Rick

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 d开发者_StackOverflowetection here
  mailItem.Subject = "Dept - " & mailItem.Subject
  myMailItem.Save

  Set mailItem = Nothing
  Set outlookNS = Nothing
End Sub 


If it is for all new messages then you can use the following

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

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

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消