Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripping HTML From A String

I've tried a number of things but nothing seems to be working properly. I have an Access DB and am writing code in VBA. I have a string of HTML source code that I am interested in stripping all of the HTML code and Tags out of so that I just have plain text string with no html or tags left. What is the best way to do this?

Thanks

like image 741
Ann Sanderson Avatar asked Oct 09 '12 16:10

Ann Sanderson


2 Answers

One way that's as resilient as possible to bad markup;

with createobject("htmlfile")
    .open
    .write "<p>foo <i>bar</i> <u class='farp'>argle </zzzz> hello </p>"
    .close
    msgbox "text=" & .body.outerText
end with
like image 102
Alex K. Avatar answered Sep 21 '22 05:09

Alex K.


    Function StripHTML(cell As Range) As String  
 Dim RegEx As Object  
 Set RegEx = CreateObject("vbscript.regexp")  

 Dim sInput As String  
 Dim sOut As String  
 sInput = cell.Text  

 With RegEx  
   .Global = True  
   .IgnoreCase = True  
   .MultiLine = True  
.Pattern = "<[^>]+>" 'Regular Expression for HTML Tags.  
 End With  

 sOut = RegEx.Replace(sInput, "")  
 StripHTML = sOut  
 Set RegEx = Nothing  
End Function  

This might help you, Good luck.

like image 20
Lior Avatar answered Sep 19 '22 05:09

Lior