0

我正在尝试从谷歌驱动器下载文件。我检查了这两个示例,但没有一个适合我:

  Sub DownloadPDF()
Dim FileNum As Long
Dim FileData() As Byte
Dim MyFile As String
Dim WHTTP As Object

On Error Resume Next
    Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
    If Err.Number <> 0 Then
        Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
    End If
On Error GoTo 0

MyFile = "https://docs.google.com/a/dink.eu/file/d/0B2P4BoDG6mdejjesiEEFMNHN0cFU/edit?usp=sharing"

WHTTP.Open "GET", MyFile, False
WHTTP.send
FileData = WHTTP.ResponseBody
Set WHTTP = Nothing

If Dir("C:\MyDownloads", vbDirectory) = Empty Then MkDir "C:\MyDownloads"

FileNum = FreeFile
Open "C:\MyDownloads\binder.pdf" For Binary As #FileNum
    Put #FileNum, 1, FileData
Close #FileNum

MsgBox "Open the folder [ C:\MyDownloads ] for the downloaded file..."
End Sub

第二个例子:

 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



 Sub DownPDF()

Dim ss As String
Dim ts As String
ss = "https://docs.google.com/a/dink.eu/file/d/0B46Ux_7O0o-4RdefsERgaEHU2YtZXM/edit?pli=1"
ts = "c:\MyDownloads\Stryker experience binder.pdf"
URLDownloadToFile 0, ss, ts, 0, 0

End Sub

例如,如果我使用以下链接http://www.bigfoto.com/sites/main/tree-winter-xxx.JPG使用普通链接,它们可以正常工作,但使用谷歌驱动器链接则不能。我该如何做才能使其与谷歌驱动器链接一起使用?

4

1 回答 1

-1

尝试在第一个示例中使用此链接格式:

https://docs.google.com/uc?export=download&id=0B2P4BoDG6mdejjesiEEFMNHN0cFU

更多帮助: http ://thebiobucket.blogspot.hu/2011/10/how-to-link-to-google-docs-for-download.html

于 2013-10-04T11:19:35.170 回答