Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DOWNLOAD csv file from web

Status
Not open for further replies.
Pretty sure we've answered this for you at least twice in the last few years, eg thread222-1819190
 
hi strongm.
i use this code but see the result in attached file:

Code:
Option Explicit
Dim NOMEFILE As String, URLFILE As String
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean

    Dim lngRetVal As Long

    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True

End Function
Private Sub ESTRAI_DATA()

    NOMEFILE = "comuni_geocoded.csv"
    URLFILE = "[URL unfurl="true"]https://github.com/gnekt/geolocalizzazione-comuni-italiani/blob/main/comuni_geocoded.csv"[/URL]
    DownloadFile URLFILE, "C:\Lavori_Vb6\COMUNI_GEOCODE\FILE\" & NOMEFILE

End Sub
Private Sub Command1_Click()

    Call ESTRAI_DATA

End Sub

 
Mainly becasue GitHub is lying to you. The file you are directly trying to download is NOT a CSV.

 
Ok
But, why if i click on link, i download the csv in a perfect csv format!

Note:
This is May other account.
 
Which link?

The comuni_geocoded.csv link on the page your URL in your original post opens another page (the page you then reference in your code). Still not a CSV.

Once on that page you CAN download the underlying CSV, by clicking on a button (rather than an A link) but that uses a piece of github payload handling code and the fact that github seems to create a temporary proxie (the raw contents) for the CSV.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top