[Solved] Get Google Drive Path on Local computer by VB code

Hello,

Is it possible to get Google drive path on Local computer by Vb code?

If yes, please share code.

Regards,
Hello Faisal,

Greetings from our website! Thank you for posting your question on the platform. Seeing our community engaging and helping each other out is always great.

There is a solution for your posted problem about getting a Google Drive path on a local computer using the VBA code. I have included a procedure called GoogleDrivePathOnLocalPC that will prompt the user for a Google Drive link, extract the folder path using the GetGoogleDrivePath function, and then save the path in a text file of your choice. The function GetGoogleDrivePath with a Google Drive link as the argument will return the path of the Google Drive folder.
VBA Code:
Code:
Sub GoogleDrivePathOnLocalPC()
    Dim chrome As Object
    Set chrome = CreateObject("Shell.Application")
    chrome.ShellExecute "chrome.exe", "https://drive.google.com/drive/my-drive", "", "", 1
    Dim link As String
    link = InputBox("Please enter a Google Drive link", "Extract Folder Path")
    Dim drivePath As String
    drivePath = GetGoogleDrivePath(link)
    If drivePath = "False" Then
        Exit Sub
    End If
    MsgBox "Drive Path: " & drivePath
    Dim desiredFile As Variant
    desiredFile = Application.GetSaveAsFilename(InitialFileName:="OutputFile.txt", FileFilter:="Text Files (*.txt), *.txt")
    Open desiredFile For Output As #1
    Print #1, drivePath
    Close #1
End Sub
Function GetGoogleDrivePath(link As String) As String
    Dim startPos As Integer
    startPos = InStr(link, "/drive/folders/")
    If startPos = 0 Then
        GetGoogleDrivePath = "Invalid Google Drive link"
        Exit Function
    End If
    startPos = startPos + Len("/drive/folders/")
    Dim endPos As Integer
    endPos = InStr(startPos, link, "/")
    If endPos = 0 Then
        endPos = Len(link) + 1
    End If
    GetGoogleDrivePath = Mid(link, startPos, endPos - startPos)
End Function

Please let me know if you have any further questions or concerns, and I'll be more than happy to assist you further.

Best regards,
Lutfor Rahman Shimanto
 

Online statistics

Members online
0
Guests online
4
Total visitors
4

Forum statistics

Threads
371
Messages
1,627
Members
705
Latest member
curioso
Back
Top