Excel macro to convert HTML entities to text

旧巷老猫 提交于 2019-12-05 20:51:16

Create a backup of the workbook.

Open the VBA editor by pressing Alt+F11.

Double-click "This Workbook" in the treeview at left under the workbook that you are working with.

Copy and paste the following:

Sub UnescapeCharacters()

    ' set this to match your case
    sheetname = "Sheet1"

    Dim sheet As Worksheet
    Set sheet = Me.Worksheets(sheetname)

    For Row = 1 To sheet.UsedRange.Rows.Count
        For Column = 1 To sheet.UsedRange.Columns.Count
            Dim cell As Range
            Set cell = sheet.Cells(Row, Column)

            ' define all your replacements here
            ReplaceCharacter cell, """, """" 'quadruple quotes required
            ReplaceCharacter cell, ",", ","
        Next Column
    Next Row

End Sub

Sub ReplaceCharacter(ByRef cell As Range, ByVal find As String, ByVal replacement As String)

    Dim result As String
    cell.Value = replace(cell.Text, find, replacement, 1, -1)

End Sub

This just iterates over every cell in the specified worksheet and replaces everything you define. The provided code replaces the two character codes you mentioned.

You can run it as a macro, or just place the caret in the "UnescapeCharacters" subroutine and hit F5.

I've made a Excel addin that has this feature: https://www.youtube.com/watch?v=DGEc6tLaKvA

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!