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:
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:
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.
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: