?
Solved

How to convert text containing html entities to normal text in an excel macro ?

Posted on 2003-03-26
2
Medium Priority
?
1,823 Views
Last Modified: 2007-12-19
I have the following macro in Excel which  I use to convert text with special characters to html entities like (&#xxxx;):

Sub HTMLEncode()
Dim rng As Range
Dim i As Integer
Dim strValue As String
For Each rng In ActiveSheet.UsedRange.Cells
If Not rng.HasFormula Then
strValue = ""
For i = 1 To Len(rng.Value)
If Asc(Mid(rng.Value, i, 1)) >= 32 And Asc(Mid(rng.Value, i, 1)) <= 123 Then
strValue = strValue & Mid(rng.Value, i, 1)
Else
strValue = strValue & "&#" & Format(Asc(Mid(rng.Value, i, 1)), "000") & ";"
End If
Next
rng.Value = strValue
End If
Next
End Sub

Now i'd like to get the exactly reverse macro which can convert text encoded in html with html entities like (&#xxxx;) to normal text with special characters as ("à" or "ö") ???

Thanx for any help.

P.
0
Comment
Question by:earcelor
[X]
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 Comments
 
LVL 9

Accepted Solution

by:
pauloaguia earned 60 total points
ID: 8214032
(somehow that macro sounds awfly familiar :))

Sub HTMLDecode()
    Dim rng As Range
    Dim i As Integer
    Dim strValue As String

    For Each rng In ActiveSheet.UsedRange.Cells
        If Not rng.HasFormula Then
            strValue = ""
            For i = 1 To Len(rng.Value)
                If Mid(rng.Value, i, 2) = "&#" Then
                    strValue = strValue & Chr(Mid(rng.Value, i + 2, 3))
                    i = i + 5
                Else
                    strValue = strValue & Mid(rng.Value, i, 1)
                End If
            Next
            rng.Value = strValue
        End If
    Next
End Sub

Hope this helps

Paulo
0
 
LVL 9

Expert Comment

by:pauloaguia
ID: 8219961
Hi earcelor,

Would you like to tell me what was wrong with my answer so I can improve myself in the future? (I'm asking because you gave me a B so something must be wrong).

Thanks.

Paulo
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

752 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