Excel chuyển đổi HTML thành văn bản

Chức năng này chuyển đổi một chuỗi được mã hóa HTML thành biểu diễn văn bản thông thường mà không phải cài đặt plugin của bên thứ ba

Public Function HtmlDecode[StringToDecode As Variant] As String
    Set oMSHTML = CreateObject["htmlfile"]
    Set e = oMSHTML.createElement["T"]
    e.innerHTML = StringToDecode
    HtmlDecode = e.innerText
End Function

Để thêm nó vào Excel

1. Nhập ALT+F11
2. Trong menu Tệp, hãy vào Chèn > Mô-đun
3. Dán chức năng ở trên – lưu nó – [CTRL+S ]
4. Chuyển về Excel thì dùng làm hàm trong Excel như vậy.

Hướng dẫn đầy đủ để đặt chức năng được đặt tại đây. https. //ủng hộ. Microsoft. com/en-us/office/create-custom-functions-in-excel-2f06c10b-3622-40d6-a1b2-b6748ae8231f

Macro Excel chuyển đổi tất cả các thực thể HTML thành tương đương có thể đọc được. Điều này bao gồm những thứ như   và " và hơn 100 thứ khác

phần

vĩ mô

Sử dụng Macro

ghi chú

vĩ mô

[Nếu mã macro ở đây không hoạt động, hãy đảm bảo tải xuống tệp mẫu và lấy mã từ đó. ]

Sub Convert_Html_Entities[]
''''''''''''''  TeachExcel.com  ''''''''''''''
'Convert HTML Entities into readable text.

Application.ScreenUpdating = False

For Each c In Selection

    'Replace the entities - one per line.
    c.Value = Replace[c.Value, """, """"]
    c.Value = Replace[c.Value, "&", "&"]
    c.Value = Replace[c.Value, "'", "'"]
    c.Value = Replace[c.Value, ""]
    c.Value = Replace[c.Value, " ", " "]
    c.Value = Replace[c.Value, "¡", "¡"]
    c.Value = Replace[c.Value, "¢", "¢"]
    c.Value = Replace[c.Value, "£", "£"]
    c.Value = Replace[c.Value, "¤", "¤"]
    c.Value = Replace[c.Value, "¥", "¥"]
    c.Value = Replace[c.Value, "¦", "¦"]
    c.Value = Replace[c.Value, "§", "§"]
    c.Value = Replace[c.Value, "¨", "¨"]
    c.Value = Replace[c.Value, "©", "©"]
    c.Value = Replace[c.Value, "ª", "ª"]
    c.Value = Replace[c.Value, "«", "«"]
    c.Value = Replace[c.Value, "¬", "¬"]
    c.Value = Replace[c.Value, "®", "®"]
    c.Value = Replace[c.Value, "¯", "¯"]
    c.Value = Replace[c.Value, "°", "°"]
    c.Value = Replace[c.Value, "±", "±"]
    c.Value = Replace[c.Value, "²", "²"]
    c.Value = Replace[c.Value, "³", "³"]
    c.Value = Replace[c.Value, "´", "´"]
    c.Value = Replace[c.Value, "µ", "µ"]
    c.Value = Replace[c.Value, "¶", "¶"]
    c.Value = Replace[c.Value, "·", "·"]
    c.Value = Replace[c.Value, "¸", "¸"]
    c.Value = Replace[c.Value, "¹", "¹"]
    c.Value = Replace[c.Value, "º", "º"]
    c.Value = Replace[c.Value, "»", "»"]
    c.Value = Replace[c.Value, "¼", "¼"]
    c.Value = Replace[c.Value, "½", "½"]
    c.Value = Replace[c.Value, "¾", "¾"]
    c.Value = Replace[c.Value, "¿", "¿"]
    c.Value = Replace[c.Value, "À", "À"]
    c.Value = Replace[c.Value, "Á", "Á"]
    c.Value = Replace[c.Value, "Â", "Â"]
    c.Value = Replace[c.Value, "Ã", "Ã"]
    c.Value = Replace[c.Value, "Ä", "Ä"]
    c.Value = Replace[c.Value, "Å", "Å"]
    c.Value = Replace[c.Value, "Æ", "Æ"]
    c.Value = Replace[c.Value, "Ç", "Ç"]
    c.Value = Replace[c.Value, "È", "È"]
    c.Value = Replace[c.Value, "É", "É"]
    c.Value = Replace[c.Value, "Ê", "Ê"]
    c.Value = Replace[c.Value, "Ë", "Ë"]
    c.Value = Replace[c.Value, "Ì", "Ì"]
    c.Value = Replace[c.Value, "Í", "Í"]
    c.Value = Replace[c.Value, "Î", "Î"]
    c.Value = Replace[c.Value, "Ï", "Ï"]
    c.Value = Replace[c.Value, "Ð", "Ð"]
    c.Value = Replace[c.Value, "Ñ", "Ñ"]
    c.Value = Replace[c.Value, "Ò", "Ò"]
    c.Value = Replace[c.Value, "Ó", "Ó"]
    c.Value = Replace[c.Value, "Ô", "Ô"]
    c.Value = Replace[c.Value, "Õ", "Õ"]
    c.Value = Replace[c.Value, "Ö", "Ö"]
    c.Value = Replace[c.Value, "×", "×"]
    c.Value = Replace[c.Value, "Ø", "Ø"]
    c.Value = Replace[c.Value, "Ù", "Ù"]
    c.Value = Replace[c.Value, "Ú", "Ú"]
    c.Value = Replace[c.Value, "Û", "Û"]
    c.Value = Replace[c.Value, "Ü", "Ü"]
    c.Value = Replace[c.Value, "Ý", "Ý"]
    c.Value = Replace[c.Value, "Þ", "Þ"]
    c.Value = Replace[c.Value, "ß", "ß"]
    c.Value = Replace[c.Value, "à", "à"]
    c.Value = Replace[c.Value, "á", "á"]
    c.Value = Replace[c.Value, "â", "â"]
    c.Value = Replace[c.Value, "ã", "ã"]
    c.Value = Replace[c.Value, "ä", "ä"]
    c.Value = Replace[c.Value, "å", "å"]
    c.Value = Replace[c.Value, "æ", "æ"]
    c.Value = Replace[c.Value, "ç", "ç"]
    c.Value = Replace[c.Value, "è", "è"]
    c.Value = Replace[c.Value, "é", "é"]
    c.Value = Replace[c.Value, "ê", "ê"]
    c.Value = Replace[c.Value, "ë", "ë"]
    c.Value = Replace[c.Value, "ì", "ì"]
    c.Value = Replace[c.Value, "í", "í"]
    c.Value = Replace[c.Value, "î", "î"]
    c.Value = Replace[c.Value, "ï", "ï"]
    c.Value = Replace[c.Value, "ð", "ð"]
    c.Value = Replace[c.Value, "ñ", "ñ"]
    c.Value = Replace[c.Value, "ò", "ò"]
    c.Value = Replace[c.Value, "ó", "ó"]
    c.Value = Replace[c.Value, "ô", "ô"]
    c.Value = Replace[c.Value, "õ", "õ"]
    c.Value = Replace[c.Value, "ö", "ö"]
    c.Value = Replace[c.Value, "÷", "÷"]
    c.Value = Replace[c.Value, "ø", "ø"]
    c.Value = Replace[c.Value, "ù", "ù"]
    c.Value = Replace[c.Value, "ú", "ú"]
    c.Value = Replace[c.Value, "û", "û"]
    c.Value = Replace[c.Value, "ü", "ü"]
    c.Value = Replace[c.Value, "ý", "ý"]
    c.Value = Replace[c.Value, "þ", "þ"]
    c.Value = Replace[c.Value, "ÿ", "ÿ"]
    c.Value = Replace[c.Value, "Œ", "Œ"]
    c.Value = Replace[c.Value, "œ", "œ"]
    c.Value = Replace[c.Value, "Š", "Š"]
    c.Value = Replace[c.Value, "š", "š"]
    c.Value = Replace[c.Value, "Ÿ", "Ÿ"]
    c.Value = Replace[c.Value, "ƒ", "ƒ"]
    c.Value = Replace[c.Value, "ˆ", "ˆ"]
    c.Value = Replace[c.Value, "˜", "˜"]
    c.Value = Replace[c.Value, " ", ""]
    c.Value = Replace[c.Value, "‌", ""]
    c.Value = Replace[c.Value, "‍", ""]
    c.Value = Replace[c.Value, "‎", ""]
    c.Value = Replace[c.Value, "‏", ""]
    c.Value = Replace[c.Value, "–", "–"]
    c.Value = Replace[c.Value, "—", "-"]
    c.Value = Replace[c.Value, "‘", "'"]
    c.Value = Replace[c.Value, "’", "'"]
    c.Value = Replace[c.Value, "‚", "‚"]
    c.Value = Replace[c.Value, "“", """]
    c.Value = Replace[c.Value, "”", """]
    c.Value = Replace[c.Value, "„", "„"]
    c.Value = Replace[c.Value, "†", "†"]
    c.Value = Replace[c.Value, "‡", "‡"]
    c.Value = Replace[c.Value, "•", "•"]
    c.Value = Replace[c.Value, "…", "…"]
    c.Value = Replace[c.Value, "‰", "‰"]
    c.Value = Replace[c.Value, "‹", "‹"]
    c.Value = Replace[c.Value, "›", "›"]
    c.Value = Replace[c.Value, "€", "€"]
    c.Value = Replace[c.Value, "™", "™"]

Next c

Application.ScreenUpdating = True

End Sub

Cài đặt ở đâu. mô-đun

Sử dụng Macro

Macro này hoạt động trên bất kỳ ô nào bạn chọn trước khi chạy nó

Nếu bạn chọn một ô, nó sẽ hoạt động trên ô đó

Nếu bạn chọn 100 ô thì sẽ chạy trên 100 ô

Ghi chú. Nếu bạn chạy macro này trên nhiều hàng cùng lúc, tùy thuộc vào tốc độ máy tính của bạn, sẽ mất nhiều thời gian

Thêm, chỉnh sửa hoặc xóa biểu tượng

Để thêm, sửa, bớt các ký hiệu, bạn muốn thay đổi các dòng có dạng như sau

c. Giá trị = Thay thế [c. Giá trị, " ", " "]

là giá trị để thay thế

" " giữ ký hiệu sẽ được sử dụng để thay thế giá trị trên. Trong trường hợp này,   sẽ được thay thế bằng dấu cách

Tất cả các ký hiệu và thay thế phải được đặt trong dấu ngoặc kép

Bạn có thể thêm hoặc xóa các dòng tùy thuộc vào tập dữ liệu của mình hoặc bạn có thể thay đổi các dòng hiện có

Để có danh sách tốt về các thực thể HTML, bạn có thể xem trang web này

ghi chú

Tải xuống tệp đính kèm để lấy macro trong Excel và chạy thử


Khóa học Excel VBA - Từ mới bắt đầu đến chuyên gia

Hơn 200 bài học video Hơn 50 giờ hướng dẫn Hơn 200 hướng dẫn Excel

Trở thành bậc thầy về VBA và Macro trong Excel và tìm hiểu cách tự động hóa tất cả các tác vụ của bạn trong Excel với khóa học trực tuyến này. [Không yêu cầu kinh nghiệm VBA. ]

Chủ Đề