Is there a way that vba can save a file to ondrive, I have a script it downloads the file from onedrive and it works perfect.
but not able to save the file on onedrive
code to download file from onedrive.
formula changes the download path
but not able to save the file on onedrive
code to download file from onedrive.
VBA Code:
With Worksheets("DownloadFiles")
With .Range("G2:G" & .Range("a" & .Rows.Count).End(xlUp).Row)
.Formula = "=SUBSTITUTE(B2,F2,""&download=1"")"
'.Formula = "=F2"
.Value = .Value
'.NumberFormat = "DD-MM-YYYY"
End With
End With
Dim mainFolder As String
mainFolder = Application.ActiveWorkbook.Path & "\" & "Income & Expenditure Downloaded Files" '"D:\Viral"
If Right(mainFolder, 1) <> "\" Then
mainFolder = mainFolder & "\"
End If
Dim lastRow As Long
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
Dim i As Long
Dim destinationFolder As String
Dim url As String
Dim errorMessage As String
For i = 2 To lastRow
destinationFolder = Cells(i, "B").Value
url = Cells(i, "G").Value
Dim objXmlHttpReq As Object
Dim objStream As Object
On Error Resume Next
Set objXmlHttpReq = CreateObject("Microsoft.XMLHTTP")
objXmlHttpReq.Open "GET", url, False, "username", "password"
objXmlHttpReq.send
If objXmlHttpReq.Status = 200 Then
Set objStream = CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.Write objXmlHttpReq.responsebody
objStream.SaveToFile mainFolder & "\" & Cells(i, "J").Value & ".xlsx", 2
'objStream.SaveToFile ThisWorkbook.Path & "\" & "Testingg2.xlsx", 2
objStream.Close
End If
Next i
End Sub
formula changes the download path
Actual file Path to Download |
https://qtechsoftware-my.sharepoint.com//p/viral_shah/EVDbH4lX5JtNndHKStx5zkQBaapuhfS1I-tT9te4dxXXsg?e=zb29v6 |
modified file path to download |
&download=1 |