I have this code and is working perfect, it downloads a excel file from onedrive, only problem is once the file is downloaded, it gives an error (ref screen shot), after download, its not opening a downloaded file
any suggestion..
any suggestion..
VBA Code:
Sub DownloadFile()
'Declare the Object and URL
Dim myURL As String
Dim WinHttpReq As Object
'Assign the URL and Object to Variables
myURL = "https://qtechsoftware-my.sharepoint.com/:x:/p/viral_shah/EQDzOJrS8EFMkvQibRv21IABkWlaehkR8wHYJm3G103-Kw?e=AyJLXT/Daily work sheet1.xlsx"
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
'Provide Access Token and PWD to the URL for getting the service from API
WinHttpReq.Open "GET", myURL, False, "abcdef", "12345"
WinHttpReq.Send
Debug.Print WinHttpReq.Status
myURL = WinHttpReq.ResponseBody
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.ResponseBody
oStream.SaveToFile "D:\Daily Work Sheet1.xlsx" , 2
oStream.Close
End If
End Sub