title: Uploading to Google drive using VBA?
body: <p>I have an MS Access database which now requires me to 'attach' documents to it.  My intention is to store the documents on Google Drive and have a link on the database for users to retrieve the documents.</p>
  
  <p>As there are many users spread through different cities, it is not practical to require them to have synced Google Drive folders.  All the users will need the ability to upload to the database/GD so my intention is to have a separate Google account for the database - with its own login details.</p>
  
  <p>example:
  User clicks button to upload file
  Save as dialog box appears and user selects file
  Database logs into its Google Drive and uploads selected file</p>
  
  <p>Lots of problems with this though, the main one being that Google Drive does not support VBA.
  If the user is logged into their own Gmail account, that will probably be another issue.</p>
  
  <p>I came across this code for vb.net on another site.</p>
  
  <pre><code>Imports System
  Imports System.Diagnostics
  Imports DotNetOpenAuth.OAuth2
  Imports Google.Apis.Authentication.OAuth2
  Imports Google.Apis.Authentication.OAuth2.DotNetOpenAuth
  Imports Google.Apis.Drive.v2
  Imports Google.Apis.Drive.v2.Data
  Imports Google.Apis.Util
  Imports Google.Apis.Services
  
  Namespace GoogleDriveSamples
  
  Class DriveCommandLineSample
  
      Shared Sub Main(ByVal args As String)
  
          Dim CLIENT_ID As [String] = "YOUR_CLIENT_ID"
          Dim CLIENT_SECRET As [String] = "YOUR_CLIENT_SECRET"
  
          '' Register the authenticator and create the service
          Dim provider = New    NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET)
          Dim auth = New OAuth2Authenticator(Of NativeApplicationClient)(provider, GetAuthorization)
          Dim service = New DriveService(New BaseClientService.Initializer() With { _
   .Authenticator = auth _
  })
  
          Dim body As New File()
          body.Title = "My document"
          body.Description = "A test document"
          body.MimeType = "text/plain"
  
          Dim byteArray As Byte() = System.IO.File.ReadAllBytes("document.txt")
          Dim stream As New System.IO.MemoryStream(byteArray)
  
          Dim request As FilesResource.InsertMediaUpload = service.Files.Insert(body, stream, "text/plain")
          request.Upload()
  
          Dim file As File = request.ResponseBody
          Console.WriteLine("File id: " + file.Id)
          Console.WriteLine("Press Enter to end this process.")
          Console.ReadLine()
      End Sub
  
  
  
      Private Shared Function GetAuthorization(ByVal arg As NativeApplicationClient) As IAuthorizationState
  
          ' Get the auth URL:
          Dim state As IAuthorizationState = New AuthorizationState( New () {DriveService.Scopes.Drive.GetStringValue()})
  
          state.Callback = New Uri(NativeApplicationClient.OutOfBandCallbackUrl)
          Dim authUri As Uri = arg.RequestUserAuthorization(state)
  
          ' Request authorization from the user (by opening a browser window):
          Process.Start(authUri.ToString())
          Console.Write("  Authorization Code: ")
          Dim authCode As String = Console.ReadLine()
          Console.WriteLine()
  
          ' Retrieve the access token by using the authorization code:
          Return arg.ProcessUserAuthorization(authCode, state)
  
      End Function
  
  End Class
  
  
  End Namespace
  </code></pre>
  
  <p>It was suggested that the IE library could be utilised to log into the Google Drive and the API calls made from the above to upload.  I don't know how to do this.  Somewhere else it was mentioned that a 'COM wrapper' may be suitable.  I don't have experience with any coding other than VBA (self taught) so am struggling to understand what the next step should be.</p>
  
  <p>If anyone has done something similar or can offer any advice, I would be grateful to hear from you.</p>