How to Insert HTML in Excel: 3 Practical Methods
In this article
You cannot directly "insert" HTML code into an Excel cell and have it render as a live webpage or formatted rich text because Excel is a spreadsheet application, not a web browser. However, you can achieve the result of getting HTML data into Excel by importing a web page, using the Power Query tool to scrape HTML tables, or using a VBA script to parse specific HTML tags. This allows you to transform raw web data into organized rows and columns for analysis.
What You'll Need
- A computer with Microsoft Excel installed (Office 365, Excel 2019, or newer is recommended for Power Query features).
- A stable internet connection if you are importing data from a live URL.
- The URL of the webpage containing the HTML data you want to extract, or a saved .html file on your local drive.
- Administrative permissions to enable the Developer tab if you intend to use VBA scripts.
Step-by-Step
Depending on whether you want to import a whole table, a specific piece of data, or automate the process, choose one of the following three methods. Note that menu labels may differ slightly depending on your version of Excel, device, or region.
Method 1: Using the "From Web" Import (Power Query)
This is the most efficient way to insert HTML tables into Excel. It uses Power Query to identify HTML <table> tags and convert them into a structured Excel table.
- Open your Excel workbook and go to the Data tab on the top ribbon.
- In the Get & Transform Data group, click on From Web.
- A dialog box will appear. Paste the full URL of the webpage containing the HTML data into the address bar and click OK.
- Excel will connect to the page and open the Navigator window. This window scans the HTML of the page for any elements defined as tables.
- On the left-hand pane of the Navigator, you will see a list of tables found on the page (e.g., "Table 0", "Table 1"). Click on each table name to see a preview of the data in the right-hand pane.
- Once you find the table you want, you have two choices: click Load to drop the data directly into your sheet, or click Transform Data to open the Power Query Editor.
- If you chose Transform Data, you can remove unnecessary columns, filter out rows, or change data types. When finished, click Close & Load from the Home tab of the editor.
Method 2: The Manual Copy-Paste Method
For simple HTML formatting or small tables, a direct copy-paste often preserves the basic HTML structure (like bolding, colors, and table borders) because Excel recognizes the HTML clipboard format.
- Open your web browser and navigate to the page containing the HTML content.
- Use your mouse to highlight the specific table or text area you wish to insert.
- Right-click and select Copy, or press Ctrl + C on your keyboard.
- Return to your Excel worksheet and select the cell where you want the top-left corner of the data to begin.
- Right-click the cell. Under Paste Options, you will see several icons. To keep the HTML formatting, choose Keep Source Formatting.
- If the data looks skewed, click the Paste Options floating button that appears after pasting and select Match Destination Formatting to strip the HTML styles while keeping the data structure.
Method 3: Using VBA to Parse HTML (Advanced)
If you need to insert specific pieces of HTML (like only the text inside <h1> tags) that aren't in a table, you can use a Visual Basic for Applications (VBA) script to scrape the HTML.
- Open Excel and enable the Developer tab (Right-click the ribbon > Customize the Ribbon > check the Developer box).
- Click on Visual Basic in the Developer tab to open the VBA Editor.
- Go to Tools > References and check the boxes for Microsoft HTML Object Library and Microsoft XML, v6.0. This allows Excel to understand HTML tags.
- Go to Insert > Module and paste a script designed to fetch a URL and parse specific tags.
- The script typically uses an
XMLHTTPobject to request the page and anHTMLDocumentobject to navigate the DOM (Document Object Model). - Run the macro by pressing F5 or clicking the Run button. The script will then write the extracted HTML content into the cells you specified in the code.
Common Mistakes
One of the most frequent errors is attempting to paste raw HTML code (e.g., <div>Hello</div>) into a cell and expecting it to render as a formatted element. Excel treats this as a literal string of text. To see the rendered result, you must use the "From Web" import or copy-paste the rendered page from a browser.
Another common mistake is ignoring the "Transform Data" step in Power Query. Many users click "Load" immediately, only to find that the HTML table contained "merged cells" or "headers" that shifted the data into the wrong columns. Taking five minutes to clean the data in the Power Query Editor prevents hours of manual fixing in the spreadsheet.
Users also often forget to update their data connections. If you use Method 1, the data is a snapshot. If the HTML source on the website changes, your Excel sheet will not update automatically unless you go to Data > Refresh All.
Tips
To keep your workbook fast, avoid importing massive HTML tables with thousands of rows if you only need a summary. Use the Transform Data option to filter the rows at the source so Excel only loads the necessary information into the memory.
If you are dealing with a website that requires a login, the "From Web" tool may fail because it cannot bypass the authentication wall. In these cases, the best approach is to log into the site in your browser, copy the HTML table manually, and paste it into Excel using the "Keep Source Formatting" option.
For those who frequently import HTML data, consider naming your queries. In the Power Query pane, right-click the query and rename it to something descriptive (e.g., "Monthly_Sales_Web_Data"). This makes it much easier to manage multiple HTML imports within a single workbook.
Troubleshooting
If the "From Web" tool does not find any tables on the page, it is likely because the website is a "Dynamic Web App" (using JavaScript/React/Angular) where the HTML is generated after the page loads. Excel's basic importer cannot execute JavaScript. To fix this, try to find the direct API source of the data or use the manual copy-paste method from the browser where the JavaScript has already rendered the content.
If you receive a "Access to the resource is forbidden" error, the website is likely blocking automated scrapers. To resolve this, check if the site has a downloadable CSV or Excel version of the data. If not, manual copying is the only reliable workaround.
If your VBA script throws a "User-defined type not defined" error, it means you missed the step of adding the Microsoft HTML Object Library in the Tools > References menu. Return to the VBA editor and ensure those libraries are checked.
If the pasted data appears as a single long string in one cell instead of multiple columns, the HTML source likely used <br> tags instead of <td> (table data) tags. In this case, use the Data > Text to Columns feature in Excel to split the data based on a specific delimiter.
Frequently Asked Questions
Can I use HTML formulas in Excel?
No, Excel does not support HTML tags within its formula language. You cannot use a formula like =HTML("<b>Text</b>") to make text bold. You must use Excel's built-in formatting tools or Conditional Formatting.
Will the HTML data update automatically?
If you used the "From Web" (Power Query) method, the data can be updated. Go to Data > Properties and you can set the table to refresh every X minutes or refresh automatically when the file opens.
How do I remove HTML tags from a cell?
If you have imported text that still contains tags like <p> or <div>, 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 remove everything inside angle brackets.
Can I export Excel data as HTML?
Yes. You can go to File > Save As and select Web Page (.htm; .html) from the file type dropdown menu. This converts your spreadsheet into a formatted HTML table.
Why does the "From Web" tool show a blank screen?
This usually happens when a website has a security layer (like Cloudflare) that prevents bots from accessing the HTML. If this happens, the automated import will not work, and you should use the manual copy-paste method.