Avatar of RWayneH
RWayneH
Flag 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?
ProgrammingOutlookVBA

Avatar of undefined
Last Comment
Subodh Tiwari (Neeraj)

8/22/2022 - Mon
Subodh Tiwari (Neeraj)

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

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
Subodh Tiwari (Neeraj)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
RWayneH

ASKER
Thanks for the help it worked!!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Subodh Tiwari (Neeraj)

You're welcome!