(if needed the documentation page of dropbox: "officialweb"/developers/documentation/http/documentation i have tried several ways but couldn't adapt successfully. Could anyone help?)
Thanks in advance!
Code:
Code: Select all
Sub UploadToDropbox()
Dim accessToken As String
Dim filePath As String
Dim fileName As String
Dim folderPath As String
Dim url As String
Dim http As Object
Dim payload As Variant
Dim currentDate As String
accessToken = "mytoken"
filePath = Environ("USERPROFILE") & "\Desktop\" & Sheets("Admin1").Range("N3").Value & ".xlsx"
fileName = Sheets("Admin1").Range("N3").Value & "-" & Format(Date, "dd. mm. yyyy") & ".xlsx"
folderPath = "/myfolder/"
url = "https://content.dropboxapi .com/2/files/upload"
Open filePath For Binary As #1
payload = Input(LOF(1), 1)
Close #1
Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "POST", url, False
http.SetRequestHeader "Authorization", "Bearer " & accessToken
http.SetRequestHeader "Dropbox-API-Arg", "{""path"": """ & folderPath & fileName & """, ""mode"": ""overwrite"", ""autorename"": true, ""mute"": false}"
http.SetRequestHeader "Content-Type", "application/octet-stream"
http.Send payload
If http.Status >= 400 Then
Sheets("Admin1").Visible = xlVeryHidden
Err.Raise 9999
End If
End Sub