GitHubのからのダウンロードCSVファイル

YasserKhalil:

私はcsvファイルをロードし、GitHubののリンクから自分のハードディスクにダウンロードしようとしています。ここに私の試みです

#If Win64 Then
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As LongLong, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As LongLong, ByVal lpfnCB As LongLong) As LongLong
#Else
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
#End If

Function DownloadFile(Url As String, SavePathName As String) As Boolean
DownloadFile = URLDownloadToFile(0, Replace(Url, "\", "/"), SavePathName, 0, 0) = 0
End Function

Sub Demo()
Dim strUrl As String, strSavePath As String, strFile As String

strUrl = "https://github.com/pcm-dpc/COVID-19/blob/master/dati-regioni/dpc-covid19-ita-regioni-20200224.csv"    'SharePoint Path For The File
strSavePath = ThisWorkbook.Path & "\"
strFile = "FileName" & Format(Date, "dd.mm.yyyy") & ".csv"

If DownloadFile(strUrl, strSavePath & strFile) Then
    MsgBox "File Saved To: " & vbNewLine & strSavePath
Else
    MsgBox "Unable To Download File:" & vbNewLine & strFile & vbNewLine & "Check URL String And That Document Is Shared", vbCritical
End If
End Sub

いくつかのファイルをダウンロードする前に、私は、コードを使用し、それがうまく働いたが、このリンク用としてダウンロードしたファイルは、HTMLページをCSVファイルではなくてです。どのように私は、CSVファイルとしてダウンロードできますか?

ライアンWildry:

そのページの生のコンテンツオプションを打ってみてください。あなたがヒットしているリンクは、HTMLマークアップを持ち、他はちょうどCSVコンテンツです。

Option Explicit

Public Sub GetCSV()
    Dim response As String

    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", "https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-regioni/dpc-covid19-ita-regioni-20200224.csv", False
        .Send
        response = .responseText
    End With

    If Trim$(response) = "" Then Exit Sub

    Open "YOURPATHHERE\SOMEFILE.csv" For Output As #1
    Print #1, response
    Close #1

End Sub

おすすめ

転載: http://10.200.1.11:23101/article/api/json?id=399468&siteId=1