I need VBA code to upload file on google drive

joedhk

New Member
Joined
Jan 19, 2019
Messages
11
Hi, does any one know how to upload file from PC to Google drive using VBA code.If any one have any idea please share.Thank you.
 
I am using 64 bit windows 10 OS.
I have built this macro using Excel 365 64-bit.
I found some issues with WebBrowser control not being able to run properly on Excel 2016, Excel 2013 and Excel 2010.
If possible, you may need to upgrade your current Excel version to at least Excel 2019 or later to run this macro. I believe Microsoft has fixed many issues related to userform controls such as WebBrowser, ListView, and TreeView, etc., since the release of Office 2019.
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi both - I suspect the issue may be the with the MSCOMCTL control. As Nguyendang points out, Microsoft has fixed issues related to the related controls (Listview, Treeview, and ProgressBar), but the real issue is that they didn't really tell anyone about it (save for a very forgettable news release back in 2016). I wrote a post about it here - it includes information on (the very unexpected) location of the control on your hard drive.

As for your workbook, @nguyendang, I've loaded it without any problems so far. I haven't gone through the process of getting the API key yet, but I don't anticipate any difficulties. I will let you know if I encounter any, but thank you so very much for sharing this solution - I'm sure a quick search of this forum will reveal that there are many people who have been asking for something like this. If you ever get bored and feel an inexplicable desire to do one for OneDrive too, the masses will surely love you!
 
Upvote 0
Hi both - I suspect the issue may be the with the MSCOMCTL control. As Nguyendang points out, Microsoft has fixed issues related to the related controls (Listview, Treeview, and ProgressBar), but the real issue is that they didn't really tell anyone about it (save for a very forgettable news release back in 2016). I wrote a post about it here - it includes information on (the very unexpected) location of the control on your hard drive.

As for your workbook, @nguyendang, I've loaded it without any problems so far. I haven't gone through the process of getting the API key yet, but I don't anticipate any difficulties. I will let you know if I encounter any, but thank you so very much for sharing this solution - I'm sure a quick search of this forum will reveal that there are many people who have been asking for something like this. If you ever get bored and feel an inexplicable desire to do one for OneDrive too, the masses will surely love you!
Hi @Dan_W - if you are interested in developing VBA solutions for working with OneDrive + SharePoint + Excel on the web (which are parts of Microsoft Graph API) or Google Sheets or Notion API, please create a new thread with questions, I will be happy to assist you.
 
Upvote 0
I re-uploaded the .xlam file as you requested.
GoogleDriveAPI.xlam
Hi!

Please, help me!
The API is too complicated for me:(
A want to download one or more files (listed in Excel (2016) worksheet's cells: "C64389 01.txt", "C65211 0003.txt" etc.) from Google Drive's directory named "JVBK" into my PC's specific folder.

I don't know what functions/procedures I need from the API:(

Can you help me?
 

Attachments

  • x01.JPG
    x01.JPG
    65 KB · Views: 8
Upvote 0
Hi!

Please, help me!
The API is too complicated for me:(
A want to download one or more files (listed in Excel (2016) worksheet's cells: "C64389 01.txt", "C65211 0003.txt" etc.) from Google Drive's directory named "JVBK" into my PC's specific folder.

I don't know what functions/procedures I need from the API:(

Can you help me?
You can call this method with alt=media to download a file stored in Drive. However, my .xlam add-in doesn't work with Excel 2016 or earlier so you need to upgrade to at least Excel 2019 or later to use this add-in.
This add-in provides the Download method in the FilesResource class module which allows you to download any file stored in Drive by FileID.
1690464814473.png
 
Upvote 0
My method isn't nearly as clever as @nguyendang's tool, but the approach I sometimes use is to make the Google Sheet publicly accessible by sharing it, and then getting the data via Power query or vba or something.
 
Upvote 0
You can call this method with alt=media to download a file stored in Drive. However, my .xlam add-in doesn't work with Excel 2016 or earlier so you need to upgrade to at least Excel 2019 or later to use this add-in.
This add-in provides the Download method in the FilesResource class module which allows you to download any file stored in Drive by FileID.
View attachment 96063
Hi!

Thanks for your reply, but this function use fileid too:(

I need a code that only needs the file name to download.
One where I enter the names of the files in the cells, and then the download takes place into a specified folder at the press of a button.
for example: download(File:="../JVBK/C65894 002.txt", Dest_Folder:="c:\downloads\JVBK_Files\")

Can you help me with this?
 
Upvote 0
Hi!

Thanks for your reply, but this function use fileid too:(

I need a code that only needs the file name to download.
One where I enter the names of the files in the cells, and then the download takes place into a specified folder at the press of a button.
for example: download(File:="../JVBK/C65894 002.txt", Dest_Folder:="c:\downloads\JVBK_Files\")

Can you help me with this?
Well, the problem is that Google Drive manages files and folders by ID, not name, so multiple files can have the same name and extension (i.e, .xlsx) in a folder but each of them must have a different ID. Therefore, you must specify an ID so that Google Drive knows what file you want to download.
 
Upvote 0
Well, the problem is that Google Drive manages files and folders by ID, not name, so multiple files can have the same name and extension (i.e, .xlsx) in a folder but each of them must have a different ID. Therefore, you must specify an ID so that Google Drive knows what file you want to download.
I saw that it is possible to create a JSON string based on the contents of a folder, which contains both the ID and the name of the file. If I received that JSON string, I could process it and extract the necessary information from it.
Folder shared with multiple people: "Google Drive: Sign-in"
Please write me a working code up to this point.
I've never used an API before, I have no idea what needs to be loaded and declared for it to work.
I'm not a beginner VBA programmer (I've written several programs for my company), but this is beyond my abilities :(
Please...
 

Attachments

  • Képkivágás.JPG
    Képkivágás.JPG
    142.7 KB · Views: 15
  • Képkivágás 2.JPG
    Képkivágás 2.JPG
    241.9 KB · Views: 15
Upvote 0
You need to implement Google Drive API.
Unfortunately, Google does not provide any client library for VBA, so I have written one on my own.
For example, design a simple userform that:
  • Uploads/download file.
  • Lists all Google Drive files in tree view.
View attachment 87660

GoogleDriveAPI.xlam
What are the steps for using it? Please advise me. Thank you very much.
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,215,456
Messages
6,124,939
Members
449,197
Latest member
k_bs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top