Skip to main content

How to convert html to text in cells in Excel?

Author: Siluvia Last Modified: 2020-06-05

As below screenshot shown, if numbers of html tags existing in your worksheet cells, how could you convert them to plain text in Excel? This article will show you two methods to remove all html tags from cells in Excel.

Convert html to text in selected cells with Find and Replace function
Convert html to text in the whole worksheet with VBA


Convert html to text in cells with Find and Replace function

You can convert all html to texts in cells with the Find and Replace function in Excel. Please do as follows.

1. Select the cells you will convert all html to texts, and press the Ctrl + F keys to open the Find and Replace dialog box.

2. In the Find and Replace dialog box, go to the Replace tab, enter <*> into the Find what box, keep the Replace with box empty, and click the Replace All button. See screenshot:

3. Then a Microsoft Excel dialog box pops up to tell you how many html tags have been replaced, click the OK button and close the Find and Replace dialog box.

Then you can see all html tags are removed from selected cells as below screenshot shown.


Convert html to text in the whole worksheet with VBA

Besides, you can convert all html to text in the whole worksheet at the same time with the below VBA code.

1. Open the worksheet contains html you will convert to text, then press the Alt + F11 keys to open the Microsoft Visual Basic for Applications window.

2. In the Microsoft Visual Basic for Applications window, click Insert > Module, then copy below VBA code into the Module window.

VBA code: Convert html to text in the whole worksheet

Sub RemoveHTMLTags()
'Update by Extendoffice 20180703
    Dim xRg As Range
    Dim xCell As Range
    Dim xStr As String
    Dim xRegEx As RegExp
    Dim xMatch As Match
    Dim xMatches As MatchCollection
    Set xRegEx = New RegExp
    Application.EnableEvents = False
    Set xRg = Cells.SpecialCells(xlCellTypeConstants)
    With xRegEx
        .Global = True
        .Pattern = "<(""[^""]*""|'[^']*'|[^'"">])*>"
    End With
    For Each xCell In xRg
        xStr = xCell.Value
            Set xMatches = xRegEx.Execute(xCell.Text)
            For Each xMatch In xMatches
                xStr = Replace(xStr, xMatch.Value, "")
            Next
        xCell.Value = xStr
    Next
   Application.EnableEvents = True
End Sub

3. Still in the Microsoft Visual Basic for Applications window, please click Tools > References, check the Microsoft VBScript Regular Expression 5.5 option in the References-VBAProject dialog box, and then click the OK button.

4. Press the F5 key or click the Run button to run the code.

Then all html tags are removed from the whole worksheet immediately.


Related articles:

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (5)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
Can we prevent the links present in the html to stop converting?
Rated 5 out of 5
This comment was minimized by the moderator on the site
Hi Yash,
I don't quite understand what your mean. Can you upload a screenshot of your data?
This comment was minimized by the moderator on the site
I believe Yash likely means he would like to retain the "src" & "href" attributes. I would suggest extracting those using formulas in adjacent columns, editing the formula values into text and then proceeding with the html to text replacement
This comment was minimized by the moderator on the site
compile error: User defined type not defined
This comment was minimized by the moderator on the site
Thanks for that sub routine - just the job!
There are no comments posted here yet
Leave your comments
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations