Text To Html

Posted on 1998-01-04
Last Modified: 2012-06-27
The following code is working proberly. The only problem is that if a string is 20 chars long, this function will only return the 20 first chars of the translated string.

Input  = "der var en gang"
Output = "der var&nb"

Function TextAsHTML2(TextToConvert As String)
 Dim N, I As Long
 Dim FoundOne As Boolean
 Dim ExtChar, HTML As Variant
 Dim strTextBuffer As String
 'Ext Lowercase
 'Ext Uppercase
 HTML = Array("­", " ", "©", "®", "™", "—", "–", "¹", "²", "³", "¶", "·", "«", "»", "¼", "½", "¾", "£", _
              "á", "â", "æ", "à", "å", "ã", "ä", "ç", "é", "ê", "è", "ð", "ë", "í", "î", "ì", "ï", "ñ", "ó", "ô", "ò", "ø", "õ", "ö", "ß", "þ", "ú", "û", "ù", "ü", "ý", "ÿ", _
              "Á", "Â", "Æ", "À", "Å", "Ã", "Ä", "Ç", "Ð", "É", "Ê", "È", "Ë", "Í", "Î", "Ì", "Ï", "Ñ", "Ó", "Ô", "Ò", "Ø", "Õ", "Ö", "Þ", "Ú", "Û", "Ù", "Ü", "Ý")
 ExtChar = Array("shy", "nbsp", "copy", "#174", "#153", "#151", "#150", "#185", "#178", "#179", "#182", "#183", "#171", "#187", "#188", "#189", "#190", "#163", _
                 "aacute", "acirc", "aelig", "agrave", "aring", "atilde", "auml", "ccedil", "eacute", "ecirc", "egrave", "eth", "euml", "iacute", "icirc", "igrave", "iuml", "ntilde", "oacute", "ocirc", "ograve", "oslash", "otilde", "ouml", "szlig", "thorn", "uacute", "ucirc", "ugrave", "uuml", "yacute", "yuml", _
                 "Aacute", "Acirc", "AElig", "Agrave", "Aring", "Atilde", "Auml", "Ccedil", "ETH", "Eacute", "Ecirc", "Egrave", "Euml", "Iacute", "Icirc", "Igrave", "Iuml", "Ntilde", "Oacute", "Ocirc", "Ograve", "Oslash", "Otilde", "Ouml", "THORN", "Uacute", "Ucirc", "Ugrave", "Uuml", "Yacute")
 strTextBuffer = ""
 For I = 1 To Len(TextToConvert)
  FoundOne = False
  For N = 1 To UBound(HTML)
   If Mid(TextToConvert, I, 1) = HTML(N) Then
     strTextBuffer = strTextBuffer & "&" & ExtChar(N) & ";"
     FoundOne = True
     Exit For  'no reason to continue if we find one.
   End If
  Next N
  If Not FoundOne Then strTextBuffer = strTextBuffer & Mid(TextToConvert, I, 1)
 Next I
 TextAsHTML2 = strTextBuffer
End Function
Question by:jfl
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Expert Comment

ID: 1449165
Your function works fine.  Try this, put at the beginning of  the Form_Load event of the main form:

   Debug.Print TextAsHTML2("der var en gang")

and test...

Author Comment

ID: 1449166
I tried that, but I only get "Stop statement encountered" from a message box.

Accepted Solution

mrmick earned 20 total points
ID: 1449167
The answer is in your immeadiate window!

Try this instead then:

MsgBox "The HTML is:" & TextAsHTML2("der var en gang")


Author Comment

ID: 1449168

I have one comment, if anyone would like to use the code don't make it replace your " " with " ". Your webpage will look very funny!

Are you always online mrmick?

I have posted a new question called "SearchWords".

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question