Excel VBA Web Scraping: What Actually Works in 2026
VBA web scraping that still works in Excel 365 - XMLHTTP requests, htmlfile parsing, JSON APIs, plus the JavaScript, WAF, and Mac walls to expect.

On this page
Half the VBA web scraping tutorials you’ll find today still open with CreateObject("InternetExplorer.Application"). That browser has been retired since June 15, 2022, when Microsoft pulled support for the IE11 desktop app. Paste those tutorials into Excel 365 and you get a zombie: sometimes it loads, more often it hangs on a page the site never finished rendering.
The current way needs no browser at all: one COM object fetches the page, a second parses it, and VBA writes the results into cells. This guide builds that whole path against quotes.toscrape.com, a site made for scraping practice, and marks exactly where VBA stops. I verified every server-side assumption against the live site on 2026-11-02 (status codes, byte counts, selector counts); the VBA code follows the documented MSXML 6 and MSHTML interfaces.
Pick your route before you write code
| Your job | Route | Why |
|---|---|---|
| Static HTML page, Excel is the destination | XMLHTTP + htmlfile parser |
About 40 lines, zero installs, runs in Excel 365 on Windows |
| Site has a JSON API behind the page | XMLHTTP + VBA-JSON | Survives redesigns far better than any HTML selector |
| One table on a plain page, no code wanted | Power Query (built in) | Two clicks, refreshable; covered in the Excel import guide |
| Page only exists after JavaScript runs | VBA is the wrong tool | No JS engine in Excel; see the limits section |
If you’re not sure whether your target needs JavaScript, load the page, press F12, view source, and search for your data. Data in the source is reachable with VBA. Data that appears only in the Elements tab is not.
The HTTP layer: one object does the job
MSXML2.XMLHTTP.6.0 has shipped with Windows since Vista and does plain GET requests fine:
Sub FetchPage()
Dim http As Object
Set http = CreateObject("MSXML2.XMLHTTP.6.0")
http.Open "GET", "https://quotes.toscrape.com/", False
http.setRequestHeader "User-Agent", _
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
http.Send
If http.Status <> 200 Then
MsgBox "Fetch failed: " & http.Status & " " & http.statusText, vbCritical
Exit Sub
End If
Debug.Print Len(http.responseText) & " bytes received"
End Sub
Running that against the practice site today fetched the full page: HTTP 200, 11,064 bytes, all ten quotes in the HTML. The site even answers that request when the User-Agent is the prehistoric Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0) string, which tells you the server does no client filtering at all. Real targets are less forgiving, which is why the header override belongs in your code by default.
Two failure modes live in this layer. First, XMLHTTP rides the same WinINET stack as Internet Explorer, so it shares the Windows proxy settings and cache of the logged-in user; the sibling object MSXML2.ServerXMLHTTP.6.0 uses the cleaner WinHTTP stack instead and is the safer pick for anything running unattended. Second, sites behind Cloudflare or similar bot filters return 403 to a WinINET request no matter what headers you send. There is no honest fix for that inside Excel. The filter is judging the client fingerprint, not the header.
Parse with htmlfile, not MSXML (the step tutorials skip)
Most older tutorials parse with MSXML2.DOMDocument and XPath. Here is why that breaks on real sites: MSXML is an XML parser, and it refuses HTML that isn’t well-formed XML. I ran the practice site’s homepage through a strict XML parse and it fails on line 10, an unclosed <link> tag in the <head>. Hacker News fails the same check. The XPath code those tutorials show never ran against the pages they claim to scrape.
Excel ships a real HTML parser instead. CreateObject("htmlfile") gives you the MSHTML document engine, the same one IE used, with querySelector support:
Sub ScrapeQuotesToSheet()
Dim http As Object, doc As Object
Dim quotes As Object, q As Object, tags As Object
Dim out() As Variant, i As Long, j As Long
Set http = CreateObject("MSXML2.XMLHTTP.6.0")
http.Open "GET", "https://quotes.toscrape.com/", False
http.setRequestHeader "User-Agent", _
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
http.Send
If http.Status <> 200 Then Err.Raise vbObjectError + 1, , "HTTP " & http.Status
Set doc = CreateObject("htmlfile")
doc.Open
doc.Write http.responseText
doc.Close
Set quotes = doc.querySelectorAll(".quote")
If quotes.Length = 0 Then Err.Raise vbObjectError + 2, , "No .quote elements found"
ReDim out(1 To quotes.Length, 1 To 3)
For i = 0 To quotes.Length - 1
Set q = quotes.Item(i)
out(i + 1, 1) = q.querySelector(".text").innerText
out(i + 1, 2) = q.querySelector(".author").innerText
Set tags = q.querySelectorAll(".tag")
For j = 0 To tags.Length - 1
out(i + 1, 3) = out(i + 1, 3) & tags.Item(j).innerText & ", "
Next j
If Len(out(i + 1, 3)) > 0 Then out(i + 1, 3) = Left$(out(i + 1, 3), Len(out(i + 1, 3)) - 2)
Next i
Range("A1:C1").Value = Array("Quote", "Author", "Tags")
Range("A2").Resize(quotes.Length, 3).Value = out
End Sub
The selectors are the load-bearing part, so I checked them against the live HTML: .quote matches 10 elements, .quote .text matches 10, small.author resolves to Albert Einstein, and the pagination link li.next a points to /page/2/, which returns HTTP 200. Same page, same structure, whether you check with a browser or a script.
One caution with htmlfile: it will execute <script> tags in whatever HTML you hand it. For pages you don’t control, strip script blocks from the response text before the doc.Write line. The flip side of using a real HTML parser: entities like come through correctly, which MSXML would have choked on.
Paginate, throttle, stay out of trouble
Pagination is a loop around the same fetch, driven by the next link. It drops into ScrapeQuotesToSheet like this:
' module level, top of file:
#If VBA7 Then
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal ms As Long)
#Else
Private Declare Sub Sleep Lib "kernel32" (ByVal ms As Long)
#End If
' inside the sub, around the fetch-parse-write block:
Dim url As String, page As Long, nextLink As Object
url = "https://quotes.toscrape.com/"
page = 0
Do While url <> "" And page < 50 ' hard cap: never trust a next link forever
page = page + 1
' ... fetch url, parse into doc, append rows ...
Set nextLink = doc.querySelector("li.next a")
If nextLink Is Nothing Then Exit Do
url = "https://quotes.toscrape.com" & nextLink.getAttribute("href")
Sleep 2000 ' 2 seconds between requests
Loop
The two-second pause is not decoration. Politeness is what keeps your IP off a blocklist, and the loop cap guards against sites whose “next” link never runs out. The legality question in this space is short: scraping public data that a page serves without login is generally lawful where you live, but terms of service can prohibit it and the courtesy rules (robots.txt, rate) are how you stay welcome. This practice site ships no robots.txt at all, meaning no declared restrictions; serious targets do publish one, and it reads in two minutes.
The kernel32 declare is Windows-only, which previews the bigger theme below.
Skip the HTML: pull the JSON API
The practice site hides a second door. Every quotes page is rendered from a JSON endpoint, and it answers without keys:
GET https://quotes.toscrape.com/api/quotes?page=1
{"has_next":true,"page":1,"quotes":[{"author":{"name":"Albert Einstein",...},
"tags":["change","deep-thoughts","thinking","world"],"text":"\u201cThe world..."}]}
I pulled it today: 10 quotes per page, has_next true on page 1, and clean top-level keys (has_next, page, quotes, top_ten_tags). Scraping the API instead of the HTML is the single biggest reliability win available, because site redesigns change CSS classes constantly and JSON contracts rarely. My notes on finding these endpoints on any site are in how to find a website’s hidden API.
VBA has no built-in JSON parser, so add VBA-JSON (2,143 stars on GitHub, MIT license): download JsonConverter.bas, then in the VBA editor use File → Import File. On Windows add a reference to Microsoft Scripting Runtime; for Mac compatibility the project asks for VBA-Dictionary instead. Then the whole scraper is:
Sub ScrapeQuotesApi()
Dim http As Object, json As Object, q As Object
Dim r As Long, page As Long
Range("A1:C1").Value = Array("Quote", "Author", "Tags")
r = 2: page = 1
Do
Set http = CreateObject("MSXML2.XMLHTTP.6.0")
http.Open "GET", "https://quotes.toscrape.com/api/quotes?page=" & page, False
http.setRequestHeader "User-Agent", _
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
http.Send
If http.Status <> 200 Then Err.Raise vbObjectError + 3, , "HTTP " & http.Status
Set json = JsonConverter.ParseJson(http.responseText)
For Each q In json("quotes")
Cells(r, 1).Value = q("text")
Cells(r, 2).Value = q("author")("name")
Cells(r, 3).Value = Join(CollectionToArray(q("tags")), ", ")
r = r + 1
Next q
page = page + 1
Loop While json("has_next") And page <= 50
End Sub
Private Function CollectionToArray(c As Object) As Variant
Dim a() As String, i As Long, v As Variant
ReDim a(1 To c.Count)
i = 1
For Each v In c
a(i) = CStr(v): i = i + 1
Next v
CollectionToArray = a
End Function
Watch one VBA-specific trap: VBA numbers carry 15 significant digits, and VBA-JSON hands back String for longer all-digit values rather than silently corrupting them. If you scrape IDs, treat them as text from the start.
What Excel VBA web scraping cannot reach
The limits are structural, not version problems. No amount of cleverness in the VBE fixes them.
JavaScript-rendered pages. htmlfile parses the HTML the server shipped; it does not run the page’s JavaScript. If the data assembles itself after load, VBA never sees it. The classic workaround was automating IE, which died with IE11’s retirement in June 2022. The living workaround is SeleniumBasic, which drives Chrome through WebDriver, but its latest release is v2.0.9.0 from March 2016, and you inherit the full chromedriver-version-matching treadmill. It works. It is also the most maintenance you can buy.
Bot filters and WAFs. WinINET’s client fingerprint is nothing like a browser’s, and filtered sites drop the request at the door. Scraper vendors sell rotating proxies and browser rendering for exactly this; none of it is reachable from a VBA module, and I wouldn’t recommend pretending otherwise.
Mac Excel. MSXML2.XMLHTTP, WinHTTP, and kernel32 are Windows COM and API calls. Excel for Mac runs VBA, and VBA-JSON parses JSON there, but the HTTP layer has no equivalent, so the fetch side needs QueryTables relics or AppleScript bridges. Excel scraping on a Mac is a weekend of workarounds, not a tutorial.
Text encoding. responseText decodes bytes using the charset the server declares. When the header omits it, accented characters arrive as mojibake. The fix is decoding responseBody yourself:
' abridged: decode UTF-8 bytes when the server omits the charset
With CreateObject("ADODB.Stream")
.Open
.Type = 1 ' adTypeBinary
.Write http.responseBody
.Position = 0
.Type = 2 ' adTypeText
.Charset = "UTF-8"
html = .ReadText
.Close
End With
None of this means VBA scraping is a dead end. It means the tool has a fence, and the fence is easy to see from the first request.
When to hand the job to a real scraper
The moment your target needs JavaScript rendering, login sessions, or selectors that survive a redesign, a purpose-built scraper pays for itself faster than one more week of VBA archaeology. Our own tool here is Magpie, a local CLI: it renders JS pages when needed, records the XHR calls pages make, and writes CSV or JSON that Excel reads with Data → Get Data. It has no Excel integration and nothing runs inside a workbook; the bridge is a file on disk. The full bridge setup is in how to import data from a website into Excel, and the CSV/JSON route is in how to scrape a website to CSV or JSON.
For Google Sheets teams the trade-offs differ enough to matter, so I keep a separate comparison in Google Sheets web scraping: IMPORTXML and beyond rather than forcing one answer on both.
FAQ
Is VBA web scraping legal? Scraping publicly served data is generally lawful, but terms of service can prohibit it, and logged-in or personal data raises privacy law questions. Check the site’s robots.txt and ToS, throttle your requests, and never automate a login you weren’t meant to (see scraping a website with login for what that takes).
Can VBA scrape JavaScript-rendered pages?
Not with the parser built into Excel. htmlfile sees only server-shipped HTML. Your options are SeleniumBasic driving a real browser, or scraping the JSON API behind the page if one exists, which is usually the better answer anyway.
Does this still work in Excel 365?
Yes. MSXML2.XMLHTTP.6.0 and the htmlfile parser ship with Windows and load fine from Excel 365 VBA on Windows. What changed is the browser automation route: IE is retired, so IE-driven scraping tutorials are dead code.
VBA or Python for web scraping? VBA wins when the whole workflow already lives in Excel and a colleague must press the button. Python wins everywhere else: requests, BeautifulSoup, and pandas cover more ground with fewer lines. The full path is in Python web scraping.
Start here
Paste ScrapeQuotesToSheet into a module and run it; you’ll have ten quotes on the grid in about two seconds. Then run ScrapeQuotesApi and compare which code you’d rather fix the day the site redesigns. When your real target turns out to need JavaScript or logins, that’s the exit ramp to the import guide, not a weekend in SeleniumBasic.


