Upload a file in onedrive

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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