Upload a file in onedrive

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,134
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
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.

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


 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,224,828
Messages
6,181,201
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top