Your objective will be difficult but not, I believe, impossible. This answer is not a solution but an explanation of how I would attempt to achieve your objective.
Have a look at this answer: How to copy Outlook mail message into excel using VBA or Macros. The questioner did not understand how complex the Html behind a simple email can be and the macro in the answer was intended to help give that understanding. I believe you have the same problem.
The macro creates a new Excel workbook and outputs selected properties of every email in Inbox to a worksheet within that workbook. In particular, it outputs the Html body as a string so you can see what it would look like to a VBA macro. The macro replaces control characters such as carriage return and linefeed with [CR] and [LF] so they are visible rather than obeyed. Copy this macro to your Outlook installation and follow the instructions for amending it so it runs on your system. Run it and look at the Html bodies of the emails you wish to edit.
To give you an idea of what you will see, I have run the macro and below I show the output for one of my emails. I have replaced each block of text with “xxx” and replaced people’s names and email addresses with their initials. The middle of that email looks like:
In your example, each email in the chain is headed: “From … Sent … To … Subject …”. Some of the emails in my example are headed: “On date at time xxx wrote”. Each email package has its own style for these headers. You will have to identify all the different headers in the emails you wish to process.
An email that has been passed through several hands might display as:
Latest text
Header 3
Text 3
Header 2
Text 2
Header 1
Original text
You want to keep “Latest text”. “Header 1” and “Original text” and discard “Header 3”, “Text 3”, “Header 2” and “Text 2”.
Finding “From: …” or “On Date …” will be the first step in finding a header but not the last step. Below are some of the headers from my sample email:
<div>[CR][LF] On Friday, 12 January 2018, 11:05:08 GMT, L <L@gmail.com> wrote:[CR][LF] </div>
<div><br clear="none">On 11 Jan 2018, at 23:44, L <<a shape="rect" href="mailto:L@gmail.com" rel="nofollow" target="_blank">L@gmail.com</a>> wrote:<br clear="none"><br clear="none"></div>
<div dir="ltr">On Thu, 11 Jan 2018, 11:02 J, <<a shape="rect" href="mailto:J@btinternet.com" rel="nofollow" target="_blank">J@btinternet.com</a>> wrote:<br clear="none"></div>
<div lang="EN-GB"><div class="ydpaff2140ayiv2245505134m_-5691341948790493700WordSection1"><div><div style="border-color: rgb(225, 225, 225) currentcolor currentcolor; border-style: solid none none; border-width: 1pt medium medium; padding: 3pt 0cm 0cm;"><p class="ydpaff2140ayiv2245505134MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> G [mailto:<a shape="rect" href="mailto:G@yahoo.co.uk" rel="nofollow" target="_blank">G@yahoo.co.uk</a>] <br clear="none"><b>Sent:</b> 11 January 2018 10:27<br clear="none"><b>To:</b> J <<a shape="rect" href="mailto:J@btinternet.com" rel="nofollow" target="_blank">J@btinternet.com</a>>; T <<a shape="rect" href="mailto:T@virginmedia.com" rel="nofollow" target="_blank">T@virginmedia.com</a>>; C <<a shape="rect" href="mailto:C@gmail.com" rel="nofollow" target="_blank">C@gmail.com</a>>; E<<a shape="rect" href="mailto:E@gmail.com" rel="nofollow" target="_blank">E@gmail.com</a>>; L <<a shape="rect" href="mailto:L@gmail.com" rel="nofollow" target="_blank">L@gmail.com</a>>; M <<a shape="rect" href="mailto:M@gmail.com" rel="nofollow" target="_blank">M@gmail.com</a>>; N <<a shape="rect" href="mailto:N@gmail.com" rel="nofollow" target="_blank">N@gmail.com</a>><br clear="none"><b>Subject:</b> xxx<u></u><u></u></span></p></div></div></div></div>
Notice 1: even when two headers are from the same person, they are not necessarily the same.
Notice 2: I have gone back to the <div>
before the start of the header’s text and the </div>
after the end of the header’s text.
Notice 2 is the important one. All emails and web pages that I have examined in recent years use this approach. The string <div>xxx</div>
says xxx is to be displayed as a block. The attributes within <div>
specify how the block is to be displayed. Each <div>
has a matching <\div>
and you must remove a complete block; that is from <div>
to its matching <\div>
. The effect of leaving a stray <div>
or <\div>
is not defined and may give strange results.
If you look at the full email below you will find:
<blockquote class="ydpaff2140ayiv2245505134gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
and
</blockquote>
This is another type of blocking which has been used to specify a line down the left side of the text. There are several <blockquote>
to <\blockquote
blocks within my example email. Since they block together text you wish to keep and text you wish to discard, you will have to remove all these tags but retain their content.
I have tried to explain the issues you will have to address. I would manually edit emails and see the effect of deleting different parts. I would experiment until I got the effect I wanted before trying to code any VBA.
Below is my sample email. Save the entire email from to to a file with a name such as “Test Email.Html”. Display this file with your browser. Alternatively, you could ignore my example email and concentrate on your own.
<html><head></head><body><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div>Hi all</div><div><br></div><div>xxx</div><div><br></div><div>xxx</div><div><br></div><div>G<br></div>[CR][LF] <div><br></div><div><br></div>[CR][LF] [CR][LF] <div id="ydpaff2140ayahoo_quoted_6195487581" class="ydpaff2140ayahoo_quoted">[CR][LF] <div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">[CR][LF] [CR][LF] <div>[CR][LF] On Friday, 12 January 2018, 11:05:08 GMT, L <L@gmail.com> wrote:[CR][LF] </div>[CR][LF] <div><br></div>[CR][LF] <div><br></div>[CR][LF] <div><div id="ydpaff2140ayiv2245505134"><div>xxx<div><br clear="none"></div><div>xxx</div><div><br clear="none"></div><div>xxx</div><div><br clear="none"></div><div>Lx<br clear="none"><br clear="none"><div id="ydpaff2140ayiv2245505134AppleMailSignature">Sent from my iPhone</div><div class="ydpaff2140ayiv2245505134yqt9119261735" id="ydpaff2140ayiv2245505134yqt17968"><div><br clear="none">On 11 Jan 2018, at 23:44, L <<a shape="rect" href="mailto:L@gmail.com" rel="nofollow" target="_blank">L@gmail.com</a>> wrote:<br clear="none"><br clear="none"></div><blockquote type="cite"><div></div></blockquote></div></div></div><div class="ydpaff2140ayiv2245505134yqt9119261735" id="ydpaff2140ayiv2245505134yqt79627"><div>xxx<div><br clear="none"></div><div>Lx<br clear="none"><br clear="none"><div id="ydpaff2140ayiv2245505134AppleMailSignature">Sent from my iPhone</div><div><br clear="none">On 11 Jan 2018, at 20:22, C <<a shape="rect" href="mailto:C@gmail.com" rel="nofollow" target="_blank">cjdallimore@gmail.com</a>> wrote:<br clear="none"><br clear="none"></div><blockquote type="cite"><div><p dir="ltr">xxx </p>[CR][LF] <p dir="ltr">xxx</p>[CR][LF] <br clear="none"><div class="ydpaff2140ayiv2245505134gmail_quote"><div dir="ltr">On Thu, 11 Jan 2018, 11:02 J, <<a shape="rect" href="mailto:J@btinternet.com" rel="nofollow" target="_blank">J@btinternet.com</a>> wrote:<br clear="none"></div><blockquote class="ydpaff2140ayiv2245505134gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div lang="EN-GB"><div class="ydpaff2140ayiv2245505134m_-5691341948790493700WordSection1"><p class="ydpaff2140ayiv2245505134MsoNormal"><span>xxx<u></u><u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span><u></u> <u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span>xxx<u></u><u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span><u></u> <u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span>J<u></u><u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span><u></u> <u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span><u></u> <u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span><u></u> <u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> G [mailto:<a shape="rect" href="mailto:G@yahoo.co.uk" rel="nofollow" target="_blank">G@yahoo.co.uk</a>] <br clear="none"><b>Sent:</b> 11 January 2018 10:27<br clear="none"><b>To:</b> J <<a shape="rect" href="mailto:J@btinternet.com" rel="nofollow" target="_blank">J@btinternet.com</a>>; T <<a shape="rect" href="mailto:T@virginmedia.com" rel="nofollow" target="_blank">T@virginmedia.com</a>>; C <<a shape="rect" href="mailto:C@gmail.com" rel="nofollow" target="_blank">C@gmail.com</a>>; E <<a shape="rect" href="mailto:E@gmail.com" rel="nofollow" target="_blank">E@gmail.com</a>>; L <<a shape="rect" href="mailto:L@gmail.com" rel="nofollow" target="_blank">L@gmail.com</a>>; M <<a shape="rect" href="mailto:M@gmail.com" rel="nofollow" target="_blank">M@gmail.com</a>>; N<<a shape="rect" href="mailto:N@gmail.com" rel="nofollow" target="_blank">N@gmail.com</a>><br clear="none"><b>Subject:</b> xxx<u></u><u></u></span></p></div></div><div lang="EN-GB"><div class="ydpaff2140ayiv2245505134m_-5691341948790493700WordSection1"><p class="ydpaff2140ayiv2245505134MsoNormal"><u></u> <u></u></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;"><u></u> <u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;">xxx<a shape="rect" href="http://www.rightmove.co.uk/property-for-sale/property-123.html?premiumA=true" rel="nofollow" target="_blank">http://www.rightmove.co.uk/property-for-sale/property-123.html?premiumA=true</a><u></u><u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;"><u></u> <u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;">xxx<u></u><u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;"><u></u> <u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;">xxx<u></u><u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;"><u></u> <u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;">xxx<u></u><u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;"><u></u> <u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;">xxx<u></u><u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;"><u></u> <u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;">G<u></u><u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><span><u></u> <u></u></span></p><p class="ydpaff2140ayiv2245505134MsoNormal"><a shape="rect" name="m_-5691341948790493700__MailEndCompose"><span><u></u> <u></u></span></a></p><span></span></div></div><div lang="EN-GB"><div class="ydpaff2140ayiv2245505134m_-5691341948790493700WordSection1"><div><div style="border-color: rgb(225, 225, 225) currentcolor currentcolor; border-style: solid none none; border-width: 1pt medium medium; padding: 3pt 0cm 0cm;"><p class="ydpaff2140ayiv2245505134MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> G [mailto:<a shape="rect" href="mailto:G@yahoo.co.uk" rel="nofollow" target="_blank">G@yahoo.co.uk</a>] <br clear="none"><b>Sent:</b> 11 January 2018 10:27<br clear="none"><b>To:</b> J <<a shape="rect" href="mailto:J@btinternet.com" rel="nofollow" target="_blank">J@btinternet.com</a>>; T <<a shape="rect" href="mailto:T@virginmedia.com" rel="nofollow" target="_blank">T@virginmedia.com</a>>; C <<a shape="rect" href="mailto:C@gmail.com" rel="nofollow" target="_blank">C@gmail.com</a>>; E<<a shape="rect" href="mailto:E@gmail.com" rel="nofollow" target="_blank">E@gmail.com</a>>; L <<a shape="rect" href="mailto:L@gmail.com" rel="nofollow" target="_blank">L@gmail.com</a>>; M <<a shape="rect" href="mailto:M@gmail.com" rel="nofollow" target="_blank">M@gmail.com</a>>; N <<a shape="rect" href="mailto:N@gmail.com" rel="nofollow" target="_blank">N@gmail.com</a>><br clear="none"><b>Subject:</b> xxx<u></u><u></u></span></p></div></div></div></div><div lang="EN-GB"><div class="ydpaff2140ayiv2245505134m_-5691341948790493700WordSection1"><p class="ydpaff2140ayiv2245505134MsoNormal"><u></u> <u></u></p><div><div><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;"><u></u> <u></u></span></p></div><div><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;">xxx<a shape="rect" href="http://www.rightmove.co.uk/property-for-sale/property-123.html?premiumA=true" rel="nofollow" target="_blank">http://www.rightmove.co.uk/property-for-sale/property-123.html?premiumA=true</a><u></u><u></u></span></p></div><div><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;"><u></u> <u></u></span></p></div><div><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;">xxx<u></u><u></u></span></p></div><div><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;"><u></u> <u></u></span></p></div><div><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;">xxx<u></u><u></u></span></p><div><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;"><u></u> <u></u></span></p></div><div><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;">xxx<u></u><u></u></span></p></div><div><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;"><u></u> <u></u></span></p></div><div><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;">xxx<u></u><u></u></span></p></div><div><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;"><u></u> <u></u></span></p></div><p class="ydpaff2140ayiv2245505134MsoNormal"><span style="font-size:10.0pt;">G<u></u><u></u></span></p></div></div></div></div></blockquote></div>[CR][LF] </div></blockquote></div></div></div></div></div>[CR][LF] </div>[CR][LF] </div></div></body></html>