We help IT Professionals succeed at work.

WildCard for deleting lines in an email message body.

RWayneH
RWayneH asked
on
161 Views
Last Modified: 2018-12-19
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?
Comment
Watch Question

Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015

Commented:
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

Author

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"
Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Thanks for the help it worked!!
Subodh Tiwari (Neeraj)Excel & VBA Expert
CERTIFIED EXPERT
Most Valuable Expert 2018
Awarded 2015

Commented:
You're welcome!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions