Tried this function to make HTML entities, it did NOTHING

hellothere4

New Member
Joined
May 9, 2011
Messages
17
Can someone explain why when I try to use this in cells it does nothing and what I can fo to fix it?:confused:

edit: sorry it actually looks like this but without spaces:

ConvertHTML = Replace(ConvertHTML, "& amp;", "&")
ConvertHTML = Replace(ConvertHTML, "& lt;", "<")
ConvertHTML = Replace(ConvertHTML, "& gt;", ">")
ConvertHTML = Replace(ConvertHTML, "& nbsp;", " ")
ConvertHTML = Replace(ConvertHTML, "& iexcl;", "¡")
ConvertHTML = Replace(ConvertHTML, "& curren;", "¤")

Function ConvertHTML(TheString As String) As String
ConvertHTML = TheString
ConvertHTML = Replace(ConvertHTML, """, Chr(34))
ConvertHTML = Replace(ConvertHTML, "&", "&")
ConvertHTML = Replace(ConvertHTML, "<", "<")
ConvertHTML = Replace(ConvertHTML, ">", ">")
ConvertHTML = Replace(ConvertHTML, " ", " ")
ConvertHTML = Replace(ConvertHTML, "¡", "¡")
ConvertHTML = Replace(ConvertHTML, "¤", "¤")
ConvertHTML = Replace(ConvertHTML, "¢", "¢")
ConvertHTML = Replace(ConvertHTML, "£", "£")
ConvertHTML = Replace(ConvertHTML, "¥", "¥")
ConvertHTML = Replace(ConvertHTML, "¦", "¦")
ConvertHTML = Replace(ConvertHTML, "§", "§")
ConvertHTML = Replace(ConvertHTML, "¨", "¨")
ConvertHTML = Replace(ConvertHTML, "©", "©")
ConvertHTML = Replace(ConvertHTML, "ª", "ª")
ConvertHTML = Replace(ConvertHTML, "«", "«")
ConvertHTML = Replace(ConvertHTML, "¬", "¬")
ConvertHTML = Replace(ConvertHTML, "*", "*")
ConvertHTML = Replace(ConvertHTML, "®", "®")
ConvertHTML = Replace(ConvertHTML, "™", "™")
ConvertHTML = Replace(ConvertHTML, "¯", "¯")
ConvertHTML = Replace(ConvertHTML, "°", "°")
ConvertHTML = Replace(ConvertHTML, "±", "±")
ConvertHTML = Replace(ConvertHTML, "²", "²")
ConvertHTML = Replace(ConvertHTML, "³", "³")
ConvertHTML = Replace(ConvertHTML, "´", "´")
ConvertHTML = Replace(ConvertHTML, "µ", "µ")
ConvertHTML = Replace(ConvertHTML, "¶", "¶")
ConvertHTML = Replace(ConvertHTML, "·", "·")
ConvertHTML = Replace(ConvertHTML, "¸", "¸")
ConvertHTML = Replace(ConvertHTML, "¹", "¹")
ConvertHTML = Replace(ConvertHTML, "º", "º")
ConvertHTML = Replace(ConvertHTML, "»", "»")
ConvertHTML = Replace(ConvertHTML, "¼", "¼")
ConvertHTML = Replace(ConvertHTML, "½", "½")
ConvertHTML = Replace(ConvertHTML, "¾", "¾")
ConvertHTML = Replace(ConvertHTML, "¿", "¿")
ConvertHTML = Replace(ConvertHTML, "×", "×")
ConvertHTML = Replace(ConvertHTML, "÷", "÷")
ConvertHTML = Replace(ConvertHTML, "À", "À")
ConvertHTML = Replace(ConvertHTML, "Á", "Á")
ConvertHTML = Replace(ConvertHTML, "Â", "Â")
ConvertHTML = Replace(ConvertHTML, "Ã", "Ã")
ConvertHTML = Replace(ConvertHTML, "Ä", "Ä")
ConvertHTML = Replace(ConvertHTML, "Å", "Å")
ConvertHTML = Replace(ConvertHTML, "Æ", "Æ")
ConvertHTML = Replace(ConvertHTML, "Ç", "Ç")
ConvertHTML = Replace(ConvertHTML, "È", "È")
ConvertHTML = Replace(ConvertHTML, "É", "É")
ConvertHTML = Replace(ConvertHTML, "Ê", "Ê")
ConvertHTML = Replace(ConvertHTML, "Ë", "Ë")
ConvertHTML = Replace(ConvertHTML, "Ì", "Ì")
ConvertHTML = Replace(ConvertHTML, "Í", "Í")
ConvertHTML = Replace(ConvertHTML, "Î", "Î")
ConvertHTML = Replace(ConvertHTML, "Ï", "Ï")
ConvertHTML = Replace(ConvertHTML, "Ð", "Ð")
ConvertHTML = Replace(ConvertHTML, "Ñ", "Ñ")
ConvertHTML = Replace(ConvertHTML, "Ò", "Ò")
ConvertHTML = Replace(ConvertHTML, "Ó", "Ó")
ConvertHTML = Replace(ConvertHTML, "Ô", "Ô")
ConvertHTML = Replace(ConvertHTML, "Õ", "Õ")
ConvertHTML = Replace(ConvertHTML, "Ö", "Ö")
ConvertHTML = Replace(ConvertHTML, "Ø", "Ø")
ConvertHTML = Replace(ConvertHTML, "Ù", "Ù")
ConvertHTML = Replace(ConvertHTML, "Ú", "Ú")
ConvertHTML = Replace(ConvertHTML, "Û", "Û")
ConvertHTML = Replace(ConvertHTML, "&UUml;", "Ü")
ConvertHTML = Replace(ConvertHTML, "Ý", "Ý")
ConvertHTML = Replace(ConvertHTML, "Þ", "Þ")
ConvertHTML = Replace(ConvertHTML, "ß", "ß")
ConvertHTML = Replace(ConvertHTML, "à", "à")
ConvertHTML = Replace(ConvertHTML, "á", "á")
ConvertHTML = Replace(ConvertHTML, "â", "â")
ConvertHTML = Replace(ConvertHTML, "ã", "ã")
ConvertHTML = Replace(ConvertHTML, "ä", "ä")
ConvertHTML = Replace(ConvertHTML, "å", "å")
ConvertHTML = Replace(ConvertHTML, "æ", "æ")
ConvertHTML = Replace(ConvertHTML, "ç", "ç")
ConvertHTML = Replace(ConvertHTML, "è", "è")
ConvertHTML = Replace(ConvertHTML, "é", "é")
ConvertHTML = Replace(ConvertHTML, "ê", "ê")
ConvertHTML = Replace(ConvertHTML, "ë", "ë")
ConvertHTML = Replace(ConvertHTML, "ì", "ì")
ConvertHTML = Replace(ConvertHTML, "í", "í")
ConvertHTML = Replace(ConvertHTML, "î", "î")
ConvertHTML = Replace(ConvertHTML, "ï", "ï")
ConvertHTML = Replace(ConvertHTML, "ð", "ð")
ConvertHTML = Replace(ConvertHTML, "ñ", "ñ")
ConvertHTML = Replace(ConvertHTML, "ò", "ò")
ConvertHTML = Replace(ConvertHTML, "ó", "ó")
ConvertHTML = Replace(ConvertHTML, "ô", "ô")
ConvertHTML = Replace(ConvertHTML, "õ", "õ")
ConvertHTML = Replace(ConvertHTML, "ö", "ö")
ConvertHTML = Replace(ConvertHTML, "ø", "ø")
ConvertHTML = Replace(ConvertHTML, "ù", "ù")
ConvertHTML = Replace(ConvertHTML, "ú", "ú")
ConvertHTML = Replace(ConvertHTML, "û", "û")
ConvertHTML = Replace(ConvertHTML, "ü", "ü")
ConvertHTML = Replace(ConvertHTML, "ý", "ý")
ConvertHTML = Replace(ConvertHTML, "þ", "þ")
ConvertHTML = Replace(ConvertHTML, "ÿ", "ÿ")
End Function
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I can't see any change it is supposed to make. All I can see is that it is replacing characters with the same exact one.
 
Upvote 0
Here is how I did it for a wee project I am working on.
This converts normal text into HTML.
Note how the ampersand is part of the HTML syntax and needs to be processed first.
Note the use of ASCII characters to convert to their HTML equivalent.
Hope this helps.

<div style="margin-top:20px;margin-bottom:20px;margin-left:50px;width:60%;border:1px solid rgb(255,215,0);"><div style="background-color:rgb(244,244,244);color:rgb(108,123,139);font-weight:bold;">  Code:<div style="font-weight:normal;border-top:1px solid rgb(255,215,0);background-color:rgb(255,255,255);padding:5px;margin-bottom:0px;font-family: Courier New, Courier, monospacefont-size:small;color:rgb(0,0,0);"><span style="color:rgb(51,102,255);">Private</span> <span style="color:rgb(51,102,255);">Sub</span> ConvertHtmlCharacters(<span style="color:rgb(51,102,255);">ByRef</span> sCode <span style="color:rgb(51,102,255);">As</span> <span style="color:rgb(51,102,255);">String</span>)
<br>   <span style="color:rgb(0,128,0);">'============================================
</span><br>   <span style="color:rgb(0,128,0);">'convert html syntax characters in code body
</span><br>   <span style="color:rgb(0,128,0);">'============================================
</span><br>   sCode = Replace(sCode, "&", "&amp;")      <span style="color:rgb(0,128,0);">'convert ampersand first
</span><br>   sCode = Replace(sCode, "<>", "&lt;&gt;")
<br>   sCode = Replace(sCode, ">", "&gt;")
<br>   sCode = Replace(sCode, "<", "&lt;")
<br>   sCode = Replace(sCode, Chr(34), "&#34;")  <span style="color:rgb(0,128,0);">'double quotes
</span><br>   sCode = Replace(sCode, Chr(39), "&#39;")  <span style="color:rgb(0,128,0);">'single quotes
</span><br><span style="color:rgb(51,102,255);">End</span> <span style="color:rgb(51,102,255);">Sub</span></div></div></div>

Edit NB: The variable is passed to the procedure by reference.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,921
Latest member
BBQKING

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top