Integrate VBA Project with Google Drive using GoogleApisVBA Library - Basic Version - ID Card Make

Integrate VBA Project with Google Drive using GoogleApisVBA Library - Basic Version - ID Card Make Hey guys welcome back to my channel if you're new here i'm longpamai and in this video i'm gonna introduce you to a custom library uh that i've created so vba developers can easily connect to google drive and manage files and folders the program comes absolutely at no cost and you can find the link to download the program from the video description in the first part of this video i'll show you how to create google cloud project we'll enable drive api setup consent screen create and download credentials.

Integrate VBA Project with Google Drive using GoogleApisVBA Library - Basic Version

And in the second part of the video we'll install the program to computer and i'll demonstrate how to use this simplified custom library in your vba program to manage google drive now let's go ahead and create a google cloud project for demonstration purpose i've created a brand new email account so that i can show everything from scratch okay so from address bar just type in google uh console.developers.google.com okay so from here you can select the.

Country um where you belong and then you need to agree terms of service if you like you can subscribe for updates as well and click on i agree and continue okay so if you already have uh products then you should be able to see them here uh which we do not have at the moment um let me just dismiss this you can click on create project from here as well or you can go and do it from the screen so let me click here and let's call this uh.

Google drive demo let me just call this google drive for bba and then um this should be the id for your project you don't have to do anything there and click on create okay so our project has been created um let's click on view now the next thing we want to do will be to enable the drive api um apis.

Or you can just go back to dashboard from here and go back to dashboard these are some of the taps we'll be visiting now so here once we come back to dashboard you can see this is the project we have created now and from the dashboard it gives you an option to enable apis and services so click on that button and look for drive here now let's enable the drive.

Okay so now uh we have enabled the drive you can disable the drive again api from here if you want or um okay now that's done now we can go ahead and create our credentials for this project so this credentials will be used from your vba project to connect to the drive api okay up to your google drive now from here um we first need to set up consent screen before we can set up the credentials okay so here uh you can either go for internal or external for now we'll go for external because we want.

Um any um for this demonstration we want anyone with google account to be able to use this keys or uh yeah click on project and here this is the consent screen so when you're launching your um you know like uh your project for the first time from your vba project uh it's gonna prompt the user so this page will be shown to the users okay for now i'm just gonna put the same name google drive demo vba like this.

And then we can add the logo as well let's select this logo and that's pretty much it i'm gonna leave the scope and everything we'll set up the scope and all from from our project and click on save okay now we can go ahead and create the credentials so here you should be able to create two type of prison cells one for user and one for service for service account service account also.

Will have a google drive of its own and then it can only access that particular drive okay but if you create this um this particular id or credentials um whoever uses the id this particular id can connect to that particular yourself google drive okay let's create this first from the drop-down you select uh whatever is applicable for us this is gonna be desktop application and let's call this um.

I'll just call this vba and then user just just for identification later on and keep this particular client id and your client secret confidential okay so now this is ready now you can download this into json file or you can hard code this as well in your code but for this project you can only use the json file okay so here's a json file that i've downloaded.

I'll just show in a moment now let's create for service as well now once we demonstrate in an example it will be more clear so let's call this service account as vba demo service and this is going to be the you know like service account email id okay and then if you want to put a description you can put it there so this is more like a a brand new user in google um this particular user will have um.

This more like a robotic robot uh account so this user will also have a driver of its own but you won't be able to see it from the google drive okay so you can programmatically um you know like load and see the files through your program only click on create so the account has been created now uh we can set up the role let's set up the role as owner and click on continue if you have more roles based on um you know like based on the.

    Account that you create then you can assign a role i'm going to leave this as it is and here you should be able to - ID Card Make

    See that this particular user also have access to this drive and then these are the owners and this is the new service account we've just created and just click on done so we have created a new service account now once you go inside this you should be able to generate um to be able to add a key let's scroll.

    Down a bit so here this section is blank now click on add key and create new key if you have existing key you can upload them as well and here you can download json or p12 this particular program can use both you can either go for p2 alpha json i'm gonna go for json okay now this particular uh json file has been automatically downloaded as you can see down here.

    And then uh click close and again keep this confidential i'm going to save this and then go back here okay so now we have these two created one for the user and one for service we have the keys downloaded now we will be able to use this uh in our program in vba now we'll call this i'll just call this service because i won't remember it later and then this is going to be the user.

    Now i'm going to copy these two files to this particular folder i'll just put this as credentials and i'll leave it here okay now uh once you download the program you should be able to see these files um all these files so you can either run this msi or the setup uh to install the program and then this is for demonstration purpose now let's go ahead and install this program using this setup.exe.

    Just follow the screen uh keep a note where this particular program is getting installed i'll just copy this and then click next next um so this program uses uh net library 4.7.2 so probably if you have like prior versions of excel like um 2007 or 3 probably you'll get a prompt to download this um net library if you you know like go with that option.

    It's automatically gonna install those for you as well along with that so just follow the screen now we have already installed that program let me run this uh the paths that i've just copied earlier now the file we're interested is this file okay this file basically is uh linked to all these um dll files uh where the functions are or methods are already stored now this is the file you can open this file after you download this.

    Now we can you know like try it out again this is very simplified so uh anyone uh even beginners in vba program can follow this let's give it a moment okay here it is so just ignore these buttons for now uh once you open up your editor uh in the sample module you'll see.

    All these codes now first and foremost you'll see that this particular file has been referenced to this tbl file that i was talking about this file here okay in the programs folder so if you install it to another folder what you can do is you can uncheck this click on ok and then you can relaunch this references and reference it to that file okay so google drive dot tbl file that's basically again linking to all the.

    Other libraries and now um first what we need to do here is you know in order for this vba program to access uh the drive we need to set up the uh here the credentials that we've downloaded so if we go to credentials folder let's try with the user first sift right click or copy this spot okay this is the user credentials that we have generated and here in this part i'm gonna put the json file.

    Path okay like this so in this parameter this is basically um

    For the file credential file and here you can specify either service or user we will go first with user this is only required the third parameter is only required when you use dot p12 file so when we created or our key here we download the json file so in case you use dot p12 you need to mention this email id as well that you use.

    For that okay so for example like this even if there is no email id for user well you're using this user um file you don't need to specify this it should be okay now uh in order to confirm that you can just run this code um it'll basically return what you've entered here okay so if you get an error probably the installation was not correct or it failed or it's not installed.

    Now let's first try it out i'm gonna go to google drive now from here i'm gonna go to drive this drive should be blank now okay so the drive is blank there's nothing in trash nothing shared okay uh so first let's try and create a folder using this vba code now let me explain this now basically this variable is linking to this particular library okay and then this is the class.

    Within that particular library now for your understanding just just say that this is uh for example like any other uh library or methods in vba and then uh like let's say this is a worksheet for example and then once you set this up you should be able to access the methods and properties associated with this particular class okay uh so this drive dot and then you know like uh this is in case service needs to be set.

    Up our connection needs to be set up to google uh service uh this this part will take care of that this will be taking care of the service or connection and this part will execute the method okay so here this particular object dot create folder and then this is the uh part where you specify what will be the name of the folder okay so let's give it a try and then we can now see the consent screen as well so i'll just call.

    This vba folder from vba something like that and now once i run this for the first time when you're running this you'll get a prompt uh the consent screen that we set up we'll see that now so i'm going to run this code now and this is the authentication screen so here it will say okay choose an account to continue to this particular remember this consent screen google drive demo vva now you select your.

    Account and then you'll get this prompt uh just ignore this because this is not verified uh project as you can see if you create a verified project then you will be able to uh you know you won't get this prompt or you can learn more from here click on advanced and then go to this just continue and then you'll get a prom uh you know like give access all this and then click on hello and then hello one more time you're.

    Allowing this program to see this this this okay now this uh if you give um you know if you continue to receive this window receive verification code you may close this window i'm just going to close this and then here it says this is the folder that has been created this is the id of that folder and then now if i go to this particular folder credentials folder you'll see there's a token saved here okay this is token that has been saved now.

    Every time this app needs to you know like do some more activity it's gonna refer to this talk until the time it expires uh so if you delete this uh token then it will you know like ask the users again to give a consent yeah okay so if i go to this folder you'll see this is a folder created from vba and once you go in there there's nothing and the next one is there is a code that is uh to list all the files in google now if i run this we can run this as.

    Well by clicking on this now this is the file name the id the parent id when it was last modified size and then the type of where is file or a folder okay so this basically lists all the files at the moment we only have one folder without any file uh so let me create a sub folder first let's say that we want to create a subfolder underneath this we can just get the idea of this and if i go back here.

    I'll specify what will be the parent id again all this um all these processes are in the same fashion this is the class and then this is the method again we pass the account credentials whatever credentials pass here and then again this one is the parent id or we want to create a folder and let's say this is vba subfolder or something like that now if i run this code we are expecting that the folder to be underneath this folder okay.

    Now run this so it says this folder has been created again we can verify this from here as well this is the folder vba subfolder has been created and if i go in here there is a vba subfolder okay so far all good um okay let me just take care of this array just give me one second just the headers this is just taking.

    Care of the headers it's not important actually okay that's fine now now we have uh you know like we've learned how to uh create a folder subfolder and return all the files now let me walk you through this particular code that returns all the files or folders um this is the code that does that now um again a reference to the clause and then you know like pause the account credentials uh this is just a set of the headers these headers okay so it's not important.

    And then coming back um so here basically this particular method these files and four folders this will um there's a typo there but uh just ignore that so basically this uh method is gonna bring back all the files or folders um you know like uh sorted by date modified and then this particular string as you can see here.

    So this is the entire string the first part here is the folder name this is the delimiter and then this id of that particular file or folder just the parent id when it was last modified the size and the type whether it's the file or it's a folder okay the main type and if i go back here this part is basically returning that and what i did here is find the last row with the data and then this part basically splits using this dilemma okay same delimiter.

    And then it splits into um splits this string this particular string into different different uh arrays and then at the end i'm just writing it down here as you can see here this part is looping from zero till whatever you know like the split return and then it's writing to cells whatever was splitted yeah it's basically that now the important thing to know here is this particular part yeah it's just returning the entire string here and then you can utilize that to.

    Split it and then maybe you can um for example let's say that you can also set in this manner that file name file name is equal to this and the file name is zero right the starting index and then the next one is file id is equal to one so you can also do in that fashion and then you can use maybe in your tree view or in other controls in your other programs.

    Okay so that's as simple as that to list all the files from there again you know like for now i have included only these attributes of the files and folders but in the next version if you want me to include more other attributes uh let me know i'll take care of that now let's try more examples uh the next one here is to upload the file okay again same account credentials uh the class or object and then the method to upload.

    The file here you can take two parameters the parent folder id and the file name full file part yeah so for that i've created some demo files here and that's for download just for upload so let's say we want to upload this particular file i'm just gonna shift right click copy the full part and put it here okay so let's say this is a file we want to upload and we want to upload to the sub folder and not to the main folder then you can.

    Just put the id here parent folder id and let me run this so if we go back here and confirm there's no data at the moment yeah okay so let's go back here and run this upload file yeah so we'll upload this file and then this is where it's gonna upload to and this will return the status this file name and then this is the list um the execution status okay.

    So upload status is true okay and the file is this that was uploaded now if we go to the drive you should see this file is here okay now if i open this it should be all good um now let's try more examples let's try to upload another type of file this is the pdf file.

    Now let's upload it to um obviously if you implement this you're not gonna copy the id and put it here like that you can refer to this variable from any of your program based on how you set it up so let me run this now we are uploading it to a folder from vba this is the pdf file says download uploaded now if we go to drive and go in here.

    To see this is the pdf file that we just uploaded okay now um let's see what's next download the file okay so here if i list the files it should have more two folders and two files yeah and if you look here at the parent id you'll see um these two this particular uh folders in this particular you know like um uh the children this is children of this basically that's what i'm just trying to say and then again this pdf uh.

    File is parent is this which is this yeah um so you can you know like easily populate this in a tree view uh if you have not seen a tree view video you should definitely check it out in the ui and ux uh user phone series um okay so now let's try and download the file let's say we want to download this particular file uh you'll have to specify the id for download download file uh.

    This class download file and here you can take the id and where you want to download the file for example we want to download here so i've already placed that file part here like this okay now if i run this code we are expecting the file this pdf file to be downloaded here okay so let's run this so it says you know it's just return the pots where it's downloaded now if i refresh.

    Now you see zero but if i refresh the folder you should be able to see so it takes the bigger files will take some more time to um you know like uh don't get downloaded i don't have pdf reader so that's why it's opening at chrome okay um so let's try to download another file so as you can see here this file is downloaded okay okay now let's go to the next one now.

    This one is to delete the files now let's say that we want to delete this particular file the pdf file you can specify this id here and again i concur themselves this uh object and the method okay uh going back here this is the file we're trying to download now i mean delete yeah now i'm gonna run this.

    Select your file here and then if you go back here as well you'll see that that pdf file has been deleted now if you go to trash you will not be able to see it in the trash okay just you know like delete it forever now uh let's try with the service account again the idea is same we will just need to specify that we are using service account instead of user so here we have user now let's say this is service account and again uh if you go here.

    You're in this particular user id and this is the drive right you do not have a way to see um there is no interface that's what i'm trying to say there's no interface to see the google drive of the service account so one way will be to give full access to any other user and then you'll be able to to see those files and folders and shared with me to whoever you give full access um so now going back here now we are specifying that okay we're going to use service account.

    DISCLAIMER: In this description contains affiliate links, which means that if you click on one of the product links, I'll receive a small commission. This helps support the channel and allows us to continuetomake videos like this. All Content Responsibility lies with the Channel Producer. For Download, see The Author's channel. The content of this Post was transcribed from the Channel: https://www.youtube.com/watch?v=t0b1U06dcio
Previous Post Next Post