Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Add HTML in Excel: Methods and Workarounds

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

You cannot natively "write" HTML code directly into a cell and have it render as a formatted webpage within Excel, because Excel is a spreadsheet application, not a web browser. However, you can add HTML to Excel by importing HTML tables from the web, opening .html files as spreadsheets, or using VBA (Visual Basic for Applications) to scrape or display HTML content. Depending on whether you want to import data from a website or create a dynamic HTML display, the method differs.

What You'll Need

  • A computer with Microsoft Excel installed (Windows or macOS).
  • An active internet connection (if importing data from a live URL).
  • An HTML file saved on your local drive (if importing a static file).
  • Administrative permissions to enable the Developer tab (if using the VBA method).

Step-by-Step

Depending on your goal, choose one of the following three primary methods. Note that menu labels may differ slightly depending on your version of Excel or your operating system.

Method 1: Importing HTML Tables from a Website

This is the most common way to "add HTML" to Excel. It allows you to extract structured data from a website's HTML table and place it directly into your cells.

  1. Open your Excel workbook and go to the Data tab on the top ribbon.
  2. Look for the Get & Transform Data section and click on From Web.
  3. A dialog box will appear. Paste the full URL of the webpage containing the HTML table you wish to import and click OK.
  4. Excel will connect to the page and open the Navigator window. This window analyzes the HTML of the page and lists all detected tables.
  5. On the left-hand pane, click through the listed tables. A preview will appear on the right, showing you exactly how the HTML data will look in your spreadsheet.
  6. Once you find the correct table, click Load to bring the data directly into your sheet, or click Transform Data if you need to clean the HTML formatting (such as removing empty columns) before importing.

Method 2: Opening a Local .html File

If you have a standalone HTML file saved on your computer, you can force Excel to interpret the HTML tags and convert them into spreadsheet rows and columns.

  1. Launch Microsoft Excel.
  2. Click on File and then select Open.
  3. Click Browse to open your file explorer.
  4. In the file type dropdown menu (usually set to "All Excel Files"), change the selection to All Files (*.*) or Web Pages.
  5. Select your .html file and click Open.
  6. Excel will parse the HTML tags. Any <table>, <tr>, and <td> tags will be converted into cells, rows, and columns automatically.

Method 3: Using VBA to Render or Extract HTML

For advanced users who need to programmatically add HTML content or scrape specific tags that the "From Web" tool misses, VBA is the necessary route.

  1. Enable the Developer tab if it is not visible. Right-click any tab on the ribbon, select Customize the Ribbon, and check the box for Developer.
  2. Click the Developer tab and select Visual Basic.
  3. In the VBA editor, go to Insert > Module.
  4. To extract HTML, you will need to add a reference to the HTML Object Library. Go to Tools > References and check the box for Microsoft HTML Object Library.
  5. Write a script using MSXML2.XMLHTTP to request the HTML source and HTMLDocument to parse specific tags. For example, you can write a loop that finds all <a> tags and lists the hyperlinks in Column A.
  6. Run the macro by pressing F5 or clicking the Run button.

Common Mistakes

One of the most frequent errors is attempting to type HTML tags (like <b>Hello</b>) directly into a cell and expecting the text to become bold. Excel treats this as a literal string of text. To change formatting, you must use the Home tab's formatting tools or a VBA script that modifies the .Font.Bold property of the cell.

Another mistake is importing a website that uses JavaScript to load its data (Dynamic HTML). The From Web tool primarily reads the static HTML source code. If the table you see in your browser is generated by a script after the page loads, Excel may report that no tables were found. In these cases, you cannot use the standard import tool and may need a specialized API or a more complex scraping tool.

Users also often forget to save the file in the correct format after importing HTML. If you open an .html file in Excel and then save it as a .html file again, you may lose some of the spreadsheet-specific functionality. Always Save As an Excel Workbook (.xlsx) to preserve your data and formulas.

Tips

To keep your imported HTML data up to date, use the Refresh feature. Instead of re-importing the data every time the website changes, go to the Data tab and click Refresh All. Excel will reconnect to the HTML source and update the values in your table automatically.

If the imported HTML data looks messy, use the Power Query Editor (accessed via Transform Data). Power Query allows you to split columns, filter out "null" values created by empty HTML tags, and change data types (e.g., converting a text-based HTML price into a currency number) before the data ever hits your spreadsheet.

For those who need to create a "dashboard" feel using HTML-like layouts, consider using Text Boxes or Shapes. While they aren't HTML, they allow you to layer content and create a visual structure that mimics a web page layout more closely than a rigid grid of cells.

Troubleshooting

If the From Web tool fails to find any tables, first check if the website requires a login. Excel's basic web importer cannot easily bypass authentication screens or CAPTCHAs. If the site is private, try copying the HTML table manually from your browser and using Paste Special > Unicode Text or HTML in Excel.

If you encounter a "Security Warning" when opening an HTML file or running a VBA macro, this is Excel's built-in protection against malicious code. To resolve this, go to File > Options > Trust Center > Trust Center Settings. Under Macro Settings, you can enable macros, but only do this for files you have created yourself or from trusted sources.

If the data imports but the characters look strange (e.g., symbols replacing accented letters), this is a character encoding issue. In the Power Query window, look for the File Origin setting and change it from the default to UTF-8. This ensures that the HTML encoding is correctly translated into Excel's format.

Frequently Asked Questions

Can I use HTML to make a clickable button in Excel?

No, you cannot use <button> tags. Instead, go to the Insert tab, select Illustrations > Shapes, draw a button, and then right-click it to Assign Macro or Link it to a URL.

Will Excel render CSS styles from an HTML import?

Excel will attempt to import basic formatting like bold text, colors, and table borders, but it ignores complex CSS (Cascading Style Sheets). Layouts, animations, and advanced positioning will be stripped away, leaving only the raw data and basic styling.

Is there a way to display a live website inside an Excel cell?

Not directly in a cell. You can use a VBA UserForm with a WebBrowser Control to create a pop-up window that renders a live site, but the cells themselves can only hold text, numbers, or formulas.

How do I remove HTML tags from a cell's text?

If you have imported text that still contains tags like <p>, you can use the Find and Replace tool (Ctrl+H). In the "Find what" box, type <*> and leave the "Replace with" box empty. This uses a wildcard to find and delete everything inside angle brackets.

Does the "From Web" tool work on Mac?

The functionality is more limited on macOS compared to Windows. While you can import some web data, the full Power Query "From Web" experience is primarily a Windows feature. Mac users often rely more on copying and pasting or using third-party plugins.