0

I select any mail to open a new mail item with a mailbody made up if the Subject, MailBody and FromSenderAddress of selected mail.

I get the signature content of the selected mail in my new mail body.

How do I eliminate the Signature content (Thanks..Regards...xxxxx.etc;) so it is not in my new mailbody.

Public Sub CreateNewMessage()

Dim objMsg As MailItem
Dim Selection As Selection
Dim obj As Object

Set Selection = ActiveExplorer.Selection

For Each obj In Selection

    Set objMsg = Application.CreateItem(olMailItem)

    With objMsg
      .To = ""
      .CC = ""
      .BCC = ""
      .Subject = ""
      .Body = "<Subject> " & obj.Subject & _ 
           " </Subject>" & vbCrLf & vbCrLf & _
           "<Mail> " & obj.Body & " </Mail>" & vbCrLf & vbCrLf & _
           "<Sender> " & obj.SenderEmailAddress & " </Sender>"
      .Sensitivity = olConfidential
      .Display
    End With

    Set objMsg = Nothing
Next
End Sub
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Abhinay
  • 27
  • 1
  • 1
  • 7
  • i don't think the signature is saved in a seperate part of the email, so detecting it would only be possible by text search. But maybe there is a hack with "ObjMail.HTMLBody = ObjMail.Body". Look at this post , there the Problem was the opposite -> http://stackoverflow.com/questions/8994116/how-to-add-default-signature-in-Outlook If somebody gives you a clean way to detect the Body, i would recommend to NOT use my comment ;) – Doktor OSwaldo Apr 22 '16 at 08:48
  • ya, the signature is included in the mail body of the selected mail. So, how to do text search of such content in the `.Body` of the `objMsg`. – Abhinay Apr 22 '16 at 09:19

1 Answers1

0

If you have a keyword in the signature, which is always the same like "best regards" you can use this:

Option Explicit

Sub DeleteAfterText()

' Deletes all text after endStr.

Dim currMail As mailitem
Dim msgStr As String

Dim endStr As String
Dim endStrStart As Long
Dim endStrLen As Long

Set currMail = ActiveInspector.CurrentItem
endStr = "Best Regards"
endStrLen = Len(endStr)

msgStr = currMail.HTMLBody
endStrStart = InStr(msgStr, endStr)

If endStrStart > 0 Then
    currMail.HTMLBody = Left(msgStr, endStrStart + endStrLen)
End If

End Sub

if you don't have a keyword, or different ones, it can be hard to find the signature

Doktor OSwaldo
  • 5,732
  • 20
  • 41