Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

VBA Download Folder from Google Drive

Status
Not open for further replies.

lardman363

Automotive
Feb 8, 2013
173
0
0
US
Hello,
I need to loop through and collect properties from folders and files on Google Drive. I have a macro that is working on folders/files on my local, so i thought it would be best to run the macro, temporarily download the file structure from Google Drive, then delete the temporary folder at the end of the macro.

I was wondering if there is a way to download a folder from Google Drive, using VBA. I found a bit of code that works for downloading a file...but I need the entire structure and I am not sure how to modify it for a folder. Any help would be greatly appreciated:)

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 = "IndividualFileIDHere"

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

(Source1, Source2)
 
Replies continue below

Recommended for you

Status
Not open for further replies.
Back
Top