I am using the codes provided by Solution to download sharepoint xlsx
It generates a file on my destination folder, but I am not able to use it. It seems to be corrupt.
Do I link the file to download wrongly?
Or is the issue an xlsm file for which the code was not designed?
Option Explicit
#If VBA7 Then
Private 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 Long
#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 DownloadFileFromWeb(strURL As String, strSavePath As String) As Long
' strSavePath includes filename
DownloadFileFromWeb = URLDownloadToFile(0, strURL, strSavePath, 0, 0)
End Function
Sub GetFile()
Dim urlName As String
urlName = "https://talanx.sharepoint.com/:x:/r/sites/LiabilityGlobalRisk/_layouts/15/Doc.aspx?sourcedoc=%7BC39E3D22-D263-4519-B6A5-33B64496F6E0%7D&file=Test.xlsm&action=default&mobileredirect=true"
Dim fName As String
fName = "J:\TEST\Test.xlsm"
URLDownloadToFile 0, urlName, fName, 0, 0
End Sub