Hello,
I would like to copy (download) a File located on a URL. This URL is located on a OneDrive Cloud space (maybe it plays a part).
I have checked that I have a R/W authorization on this file, granted by the owner of the Drive.
Moreover, this file is an Excel Workbook that I can open and load in my Internet browser (works fine).
Now I would like to copy it by a VBA code. I have used code we can easily find in many places, given below.
Unfortunately, it does not work for me.
By any chance, would you know how to copy an Excel Workbook from a OneDrive location to a local directory ? ...Thanks in advance
Option Explicit
Declare PtrSafe Function URLDownloadToFile _
Lib "urlmon" Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As LongPtr
Private Const ERROR_SUCCESS As Long = 0
Public Function DownloadFile(ByVal sURL As String, ByVal sLocalFile As String) As Boolean
Dim lngRetVal As LongPtr
DownloadFile = URLDownloadToFile(0&, sURL, sLocalFile, 0&, 0&) = ERROR_SUCCESS
End Function
Option Explicit
Declare PtrSafe Function URLDownloadToFile _
Lib "urlmon" Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As LongPtr
Private Const ERROR_SUCCESS As Long = 0
Public Function DownloadFile(ByVal sURL As String, ByVal sLocalFile As String) As Boolean
Dim lngRetVal As LongPtr
DownloadFile = URLDownloadToFile(0&, sURL, sLocalFile, 0&, 0&) = ERROR_SUCCESS
End Function
Sub go()
DownloadFile "https://d.docs.live.net/181eeee77f46f4563/Documents/file.xlsm", "C:\file.xlsm"
End Sub