Read contents of online excel file

strooman

Active Member
Joined
Oct 29, 2013
Messages
333
Office Version
  1. 2016
Platform
  1. Windows
This is just a question out of curiosity. It's about reading files that are stored online like txt, log or csv files. I know I can download these files and do my thing but that's not the issue here.
When I run this code for example I can read the information in the online stored txt file and print the result to the immediate window:

Code:
Sub testing()
'Requires references. Hit Alt+F11 | Tools | References | and check:
'Microsoft HTML Object Library
'Microsoft XML, v6.0
Dim XMLPage As New MSXML2.XMLHTTP60
Dim htmlDoc As New MSHTML.HTMLDocument
Dim URL As String
    
    URL = "https://www.yourwebsite.com/customers.txt"
    XMLPage.Open "GET", URL, False
    XMLPage.send
    
    htmlDoc.body.innerHTML = XMLPage.responseText
	
	'Do something with the information
    debug.print htmlDoc.body.innerHTML
End Sub

I can also read the file when it has csv or log extension.
But when it's an online excel file with xlsx extension this fails and I get crippled data. That's obvious because it's an excel file.

When I use:
Code:
oConn.Open "Provider=Microsoft.ACE.OLEDB.12.0;" & _
"Data Source=" & ThisWorkbook.FullName & ";" & _
"Extended Properties='Excel 12.0 Macro;HDR=YES'"

or use the ODBC driver then I can only read local excel files. Replacing the Data Source with an Url gives an error.

So, what's the best approach to read an online excel file that is stored in (for example)
https://www.mywebsite.com/customers.xlsx

I would emphasise again that I know that I can download that file but that is not where my interest is.
 
Last edited:

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
You can't. Your first example still downloads the result but as it's text you can read it in the immediate window.when returning binary files, you can't - they need saving. This is especially true if trying to read them with something like ado which does not work over http
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top