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.JPG it works perfectly but with google drive links it doesn't. How can I do to make it work with google drive links?

up vote -1 down vote accepted

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

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Shadwell Oct 4 '13 at 11:44
  • from site : thebiobucket.blogspot.hu/2011/10/… : "docs.google.com/uc?export=download&id=YourIndividualID You can copy your individual file id from within the "Share..."-dialogue. Here you also need to put the share settings to "public" or to "anyone with the link" " – gyap Oct 9 '13 at 8:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.