Excel VBA Connection With Google Drive

Hellow Experts,

Please kindly guide if there is some way that we can upload file to Google Drive Directly like CDO email.

Regards,
WiseOwl ExcelAsked:
Who is Participating?
 
aikimarkConnect With a Mentor Commented:
i dont understand kindly guide with Example
How much experience do you have with VBA code?

I like this example.  It is very explanatory
http://ramblings.mcpher.com/Home/excelquirks/dbabstraction/jsaonapivba


This is an example from Planet Source Code, invoking VBA code in an MS Access environment.  The entire database is available for download.
https://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=74547&lngWId=1
Function SimpleUpload(FileName As String) As Boolean
    Dim http As Object, URL As String
    Dim fileData As String, rspTxt As String
    Dim fName As String
    If Token = "" Then Exit Function
    
    ' get only file name
    fName = GetFileName(FileName)
    ' Get token
    URL = "https://www.googleapis.com/upload/drive/v2/files?uploadType=media"
    ' Read and get file
    fileData = ReadBinaryFile(FileName)
    
    Dim jSon As New clsJSONScript
        
    'Post the data To the destination URL
    'Create XMLHTTP/ServerXMLHTTP/WinHttprequest object
    'You can use any of these three objects.
    'Set http = CreateObject("WinHttp.WinHttprequest.5")
    Set http = CreateObject("MSXML2.XMLHTTP")
    With http
        'Open URL As POST request
        .Open "POST", URL, False
    
        'Set Content-Type header
        .Setrequestheader "Authorization", Token
        .Setrequestheader "Content-Type", GetMimeType(fName)
        .Setrequestheader "Content-Length", GetFileSize(FileName)
  
        'Send the form data To URL As POST binary request
        .Send (fileData)
        
        rspTxt = .ResponseText
        If .Status <> 200 Then
            '// Error getting OAuth2 token
            'err.Raise vbObjectError + .Status, Description:="Failed to retrieve data " + .Status & ": " + .ResponseText
            SimpleUpload = False
            GoTo ErrHandler
        End If
        
        SimpleUpload = True
        ' Now we have to change the file name to the orginal file...
        URL = "https://www.googleapis.com/drive/v2/files/" & GetFileID(rspTxt)
        .Open "PATCH", URL, False
        .Setrequestheader "Authorization", Token
        .Setrequestheader "Content-type", "application/json"
        .Send (Utf8BytesFromString("{'title': '" & fName & "'}"))
        rspTxt = .ResponseText
        If .Status <> 200 Then
            '// Error getting OAuth2 token
            'err.Raise vbObjectError + .Status, Description:="Failed to retrieve data " + .Status & ": " + .ResponseText
            SimpleUpload = False
            Debug.Print .ResponseText
            GoTo ErrHandler
        End If
    End With
ErrHandler:
    Err.clear
    Set http = Nothing
    Set jSon = Nothing
End Function

Open in new window


Here is a different repository for handling the oAuth part of the Google connection.
https://github.com/VBA-tools/VBA-Web/wiki/Google-APIs
0
 
Bill PrewCommented:
By far the easiest way is to install the Google Drive windows sync software on your computer.  Once you sign in to your account and set it up, you can just copy files to and from a local path as if it was a normal windows folder.  The default location is "C:\Users\Username\Google Drive" where Username is the computer user name.

https://www.google.com/drive/download/


»bp
0
 
aikimarkCommented:
You might use their REST API
https://developers.google.com/drive/v2/reference/

In the VBA code, you will probably use the MSXML2 object.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
WiseOwl ExcelAuthor Commented:
Respected Aikimark

Please Guide in Full i dont understand kindly guide with Example if Possible.

Regards,
0
 
WiseOwl ExcelAuthor Commented:
@Bill Prew Sir,

Thanks for Input i kow this methode but this is not what i am looking for and Post Question. I Need Code to Upload file to Google Drive Driectly without app via VBA if Possible Please input your Expert Comment and Oblige.

Regards,
0
 
Bill PrewCommented:
Direct interface to Google via RESTful API is a much larger undertaking, I can't take that on as part of a question.  There are authentication tokens to be established and used, and JSON strings to be parsed.  All doable, but a lot of code to build as a question answer, for me...

Feels more like a potential Gig...


»bp
0
 
WiseOwl ExcelAuthor Commented:
Respected @Aikimark

Thanks For Coding but this Function is Completely not understandable and Usable for me if you kindly let me know how to use it it would be great help.

Regards,
0
 
WiseOwl ExcelAuthor Commented:
Respected @Bill Prew,

Your Reply seems you have Sour Ability to do it please kindly help me and the community in this regard and help us to upload simple file to google drive via Excel VBA Simple Coding it would be your remarkable help to community at least for myself.

Regards,
0
 
aikimarkCommented:
Please answer my question about your VBA experience
0
 
WiseOwl ExcelAuthor Commented:
Basic  To Intermediate Level in  VBA and Still Learning to Advance Concepts.
0
 
aikimarkCommented:
If you are an intermediate level, you should be able to understand the links and code.  If you aren't at that level, you need to engage someone who can do all the work for you.  Question threads, like this one, assume that the person asking the questions has the ability to test the posted solutions, ask questions about the posted solutions, and evaluate their effectiveness (pick the best one(s)).

Question threads are not a do-my-work-for-me kind of place.
1
 
WiseOwl ExcelAuthor Commented:
Dear Sir @aikimark,

Thank you for your kind input and Words however i feel these are a bit Rude to me  anyhow i am asking more it dose not mean i have  not give try to Code i checked Link where Access Projects there as i have no command over access also there are some kind of Google APIs Connection and Client ID and Client Secret where to get it ... i already give a try to codes but didn't understand well thats why i ask... i just need some Expert Assistance to Understand this thats why i post Question over Expert-Exchange.Com.

Thanks You for Your Time and Input.

Regards,
0
 
aikimarkCommented:
If you need more expert assistance, you can try EE Gigs, EE Live, or click the Report Question link and ask for more expert participation.

As Bill Prew already stated, this isn't a trivial process.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.