vba 从谷歌驱动器下载文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18527928/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
download file from google drive
提问by Iban Arriola
I am trying to donwload a file from google drive. I check for these two examples but no one works for me:
我正在尝试从谷歌驱动器下载文件。我检查了这两个示例,但没有人对我来说有效:
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
The second example:
第二个例子:
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
With normal links they works for example if I use the following link http://www.bigfoto.com/sites/main/tree-winter-xxx.JPGit works perfectly but with google drive links it doesn't. How can I do to make it work with google drive links?
使用普通链接,例如,如果我使用以下链接http://www.bigfoto.com/sites/main/tree-winter-xxx.JPG,它可以正常工作,但使用 google 驱动器链接则不行。我怎样才能使它与谷歌驱动器链接一起工作?
采纳答案by gyap
Try to use this link format in the first example:
尝试在第一个示例中使用此链接格式:
https://docs.google.com/uc?export=download&id=0B2P4BoDG6mdejjesiEEFMNHN0cFU
more help: http://thebiobucket.blogspot.hu/2011/10/how-to-link-to-google-docs-for-download.html
更多帮助:http: //thebiobucket.blogspot.hu/2011/10/how-to-link-to-google-docs-for-download.html