Download using VBA of OneDrive file is getting Access denied error RRS feed

  • Question

  • In trying do download a file from OneDrive, I am getting Access denied error on WinHttpReq.Open line below even though Office 365 login and password are correct. Is the login and password different from the Office 365 login? I don't want to have to set up a synced local folder.

    Dim WinHttpReq As Object
    Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
    WinHttpReq.Open "GET", myURL, False, myLogin, myPassword

    myURL = WinHttpReq.ResponseBody
    If WinHttpReq.Status = 200 Then
        Set oStream = CreateObject("ADODB.Stream")
        oStream.Type = 1
        oStream.Write WinHttpReq.ResponseBody
        oStream.SaveToFile ("C:\file.csv")
    End If

    Monday, October 28, 2019 2:56 AM