Link to home
Start Free TrialLog in
Avatar of RWayneH
RWayneHFlag for United States of America

asked on

WildCard for deleting lines in an email message body.

Use the following line to delete items from an email message .body.

myforward.Body = Replace(myforward.Body, "From: batchsd <batchsd@Haworth.com>", "")

Open in new window


Is there a way to add a wildcard to this?  So everything after From: is deleted too?  I have lines that are not static.  Any ideas?
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Try placing the following function on a Standard Module...

Function ReplacedBody(str As String) As String
With CreateObject("VBScript.RegExp")
   .Global = False
   .Pattern = "(.*)From:.*"
    If .test(str) Then
       ReplacedBody = .Replace(.Execute(str)(0), "$1")
    End If
End With
End Function

Open in new window

And then use this like below and see if that works for you...

myforward.Body = ReplacedBody(myforward.Body)

Open in new window

Avatar of RWayneH

ASKER

Thanks
Ah, this hosed the whole message body, I just want to remove the line that has the "Sent:" in it.  Just like:

myforward.Body = Replace(myforward.Body, "To: SAPDocuments <SAPDocuments@Haworth.com>", "")

Open in new window


only get rid of the: "To: SAPDocuments <SAPDocuments@Haworth.com>"

The actual text that I am trying to remove is: Sent: Monday, December 17, 2018 3:47 AM
As you can see anything after the Sent: is a date and is changes.  by getting rid of the line, perhaps wildcarding to the AM or PM?

"Sent: * AM"  or PM"
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RWayneH

ASKER

Thanks for the help it worked!!
You're welcome!