View Single Post
  #29   Report Post  
Posted to microsoft.public.excel.worksheet.functions
AFSSkier AFSSkier is offline
external usenet poster
 
Posts: 94
Default With a Function, how can I get rid of formating codes like <di

Ron,

From your latest UDF works awesome! Thank you very much for your time a
efforts.

Kevin


"Ron Rosenfeld" wrote:

On Mon, 01 Jun 2009 22:56:42 -0400, Ron Rosenfeld
wrote:

On Mon, 1 Jun 2009 18:20:02 -0700, AFSSkier
wrote:

Ron,

You're getting closer. However, the & HTML codes need to be replaced, not
stripped.

&(amper)nbsp = " " (space)
&(amper)amp = & (and)

--
Thanks, Kevin


Kevin,

Also, there are, according to one source, 53 ampersand codes. If you want to
be able to replace all of them, we will need to set up an array, or lookup
table, to do so. Not difficult, just tedious.
--ron


Here's one method that first replaces all of the ampersand codes with their
ASCII equivalents, and then strips out the <... codes.

It assumes that the ampersand codes do NOT have any included spaces. (If they
do, different coding will be required).

If you copy this, be aware that the lines making up the array should all be on
one single line. Your newsreader (or mine) may insert inadvertent line breaks
that you will need to remove to make it work correctly.

=================================
Option Explicit
Function StripFormat(S As String) As String
Dim AmpCodes, AmpChars
Dim i As Long
Dim sTemp As String
Dim re As Object

AmpCodes = Array(""", "&", "<", "", " ", "¡",
"¢", "£", "¤", "¥", "¦", "§", "¨",
"©", "ª", "«", "¬", "*", "®", "¯", "°",
"±", "&sup2", "³", "´", "µ", "¶", "·",
"¸", "¹", "º", "»", "¼", "½", "¾",
"¿", "×", "÷", "Ð", "ð", "Þ", "þ",
"Æ", "æ", "Œ", "œ", "Å", "Ø", "Ç",
"ç", "ß", "Ñ", "ñ")

AmpChars = Array("""", "&", "<", "", " ", "¡", "¢", "£", "¤", "¥", "¦", "§",
"¨", "©", "ª", "«", "¬", "*", "®", "¯", "°", "±", "²", "³", "´", "µ", "¶", "·",
"¸", "¹", "º", "»", "¼", "½", "¾", "¿", "×", "÷", "Ð", "ð", "Þ", "þ", "Æ", "æ",
"Œ", "œ", "Å", "Ø", "Ç", "ç", "ß", "Ñ", "ñ")

'Replace HTML Ampersand Codes
sTemp = S
For i = 0 To UBound(AmpCodes)
sTemp = Replace(sTemp, AmpCodes(i), AmpChars(i))
Next i

'Strip out < codes; CR and LF
Set re = CreateObject("vbscript.regexp")
re.Global = True
re.Pattern = "<[^<]+|[\r\n]"
StripFormat = re.Replace(sTemp, "")
End Function
=====================================

--ron