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?
RWayneHAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
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

RWayneHAuthor Commented:
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"
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Change the existing function to this........

Function ReplacedBody(str As String) As String
With CreateObject("VBScript.RegExp")
   .Global = False
   .Pattern = "Sent:.*(AM|PM)"
    If .test(str) Then
        ReplacedBody = Replace(str, .Execute(str)(0), "")
    End If
End With
End Function

Open in new window


myforward.Body = ReplacedBody(myforward.Body)

Open in new window

This will return everything before and after Sent: <DateStamp String>

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RWayneHAuthor Commented:
Thanks for the help it worked!!
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.