?
Solved

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

Posted on 2003-03-26
2
Medium Priority
?
2,044 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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

571 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