Option Explicit
#If Win64 Then
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" ( _
ByVal pCaller As LongLong, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As LongLong, _
ByVal lpfnCB As LongLong) As LongLong
#Else
Private Declare 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 Long
#End If
Function DownloadFile(Url As String, SavePathName As String) As Boolean
DownloadFile = URLDownloadToFile(0, Replace(Url, "\", "/"), SavePathName, 0, 0) = 0
End Function
Sub Demo()
Dim strUrl As String, strSavePath As String, strFile As String
strUrl = "https://company.sharepoint.com/personal/User_domain_com/Documents/file.xlsx" 'SharePoint Path for the file
strSavePath = "C:\Test\" 'Folder to save the file
strFile = "FileName" & Format(Date, "dd.mm.yyyy") & ".xlsx"
If DownloadFile(strUrl, strSavePath & strFile) Then
MsgBox "File saved to: " & vbNewLine & strSavePath
Else
MsgBox "Unable to downloaf file:" & vbNewLine & strFile & vbNewLine & "Check url string and that document is shared", vbCritical
End If
End Sub