0

I'm using this VBA code to populate a website text area from HTML emails in outlook.

I would like to remove HYPERLINK "website"website and HYPERLINK "mailto:email@email.com"email@email.com from mailitem.body while retaining text.

How should I do it?

ie.document.getElementById("message").Value = Replace(objItem.Body, vbCrLf & vbCrLf, vbCrLf)

some examples:

www.google.com

comes out in the textarea as HYPERLINK "www.google.com"www.google.com emails come out was HYPERLINK "mailto:dr_patso@email.com"dr_patso@email.com

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
dr_patso
  • 21
  • 7
  • regular expressions? It would be helpful, if you could post an example text you extracted (shortened of course, but with the full hyperlinks. –  Oct 02 '12 at 21:10
  • Hi Johanness, I added some examples.. but website and email would be the normal text you see. Im going nuts, objitem.body is supposed to present the body in clear text it doesn't at all, EVER.. but this is my last hurdle.. – dr_patso Oct 02 '12 at 21:30
  • `mailitem.Body` is the text body which will have been created from the html body by removing formatting commands and converting links to text. Try `mailitem.HtmlBody`. – Tony Dallimore Oct 06 '12 at 16:14
  • As an alternative, look at this question: http://stackoverflow.com/q/11876549/973283. This question is nothing like yours but my answer includes a routine that creates an Excel workbook that contains the text and html bodies of all messages in the Inbox. Running that macro would be an easy way to see the bodies of a selection of emails and perhaps help you refine your question. – Tony Dallimore Oct 06 '12 at 16:26

1 Answers1

0

use this,, start using "txt" instead of objitem.body for populating.

If objItem.BodyFormat = olFormatHTML Then
txt = objItem.Body
strt = InStr(txt, "HYPERLINK")
do until strt = 0
  nd = InStr(strt + 13, txt, """")
  txt = Left(txt, strt - 1) & Mid(txt, nd + 1)
  strt = InStr(txt, "HYPERLINK")
loop
End If

If objItem.BodyFormat = olFormatRichText Then
txt = objItem.Body
strt = InStr(txt, " HYPERLINK")
do until strt = 0
  nd = InStr(strt + 13, txt, """")
  txt = Left(txt, strt - 1) & Mid(txt, nd + 2)
  strt = InStr(txt, " HYPERLINK")
loop
End If

then populate text area with body..

If objItem.BodyFormat = olFormatHTML Then ie.document.getElementById("message").Value = Replace(txt, vbCrLf & vbCrLf, vbCrLf) End If If objItem.BodyFormat = olFormatPlain Then ie.document.getElementById("message").Value = objItem.Body End If If objItem.BodyFormat = olFormatRichText Then ie.document.getElementById("message").Value = txt End If

dr_patso
  • 21
  • 7