'Get files from Sharepoint / Onedrive via VBA

The code below uses FSO to read a file containing information such as version, date and file path on a local network, and download a file according to local file current version. But I would like to adapt to work with OneDrive so I can protect it against modifications.

I see that Map to Drive doesn't work anymore, so it would have to use Graph API and I have no idea how to work with APIs. Any help would be appreciated.

Option Explicit
Const qpath As String = "\Desktop\Folder1\versioncontrol.txt"

Sub check_updates()
Dim FSO As FileSystemObject, qfile As Object
Dim mydat As String, buildt As Date, svr_build As String, svr_dat As String, svr_file As String, dlpath As String
Dim versionread As String, versionreadunwind As Variant
Dim hasupdate As Boolean, response As Integer


Set FSO = CreateObject("Scripting.FileSystemObject")
On Error GoTo ErrorHandler
Set qfile = FSO.OpenTextFile(Environ("USERPROFILE") & qpath, 1)

mydat = ThisWorkbook.Names("buildt").RefersToRange
If Not qfile.atendofstream Then
    versionread = qfile.readline
    versionreadunwind = Split(versionread, ";")
    svr_build = versionreadunwind(0)
    svr_dat = versionreadunwind(1)
    svr_file = versionreadunwind(3)
    
    If svr_dat > mydat Then hasupdate = True
    
End If

qfile.Close
Set qfile = Nothing

If hasupdate Then
    response = MsgBox("MSG HERE" & vbNewLine & _
    "Deseja atualizar agora?", vbQuestion + vbYesNo + vbDefaultButton1)
    If response = vbNo Then
        Exit Sub
    End If

    If FSO.FileExists(svr_file) Then
        dlpath = ThisWorkbook.Path & "\" & "fileprefix " & svr_build & ".xlsm"
        FileCopy svr_file, dlpath
    Else
        MsgBox "MSG HERE" & vbNewLine & _
        "SEQUENCE", vbInformation
        Exit Sub
    End If
Else
    Exit Sub
End If

MsgBox "MSG HERE" & vbNewLine & _
        "SEQUENCE", vbInformation
Shell "explorer """ & ThisWorkbook.Path & "\", vbNormalFocus

ErrorHandler:
Set FSO = Nothing
End Sub


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source