KodingKyle
New Member
- Joined
- Oct 15, 2015
- Messages
- 1
I am trying to download a file via Webdav in VBA and it works for Excel 2010 and 2007, but does not seem to be working for Excel 2013 (may have to remove "PtrSafe" to get 2007 to work). When I run the code in Excel 2013, the file does not download to my computer and I get the "Failure" message box. The value of lngRetVal is -2147221020 in this case. For Excel 2010 and 2007, the file downloads to my computer. Any thoughts on why it does not work with Excel 2013?
Code:
[/COLOR]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
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then
If Dir(LocalFilename) <> vbNullString Then
DownloadFile = True
End If
End If
End Function
Private Sub CommandButton3_Click()
If ThisWorkbook.DownloadFile([File location on server], [local directory To save file]) Then
MsgBox "Success!"
Else
MsgBox "Failure"
End If
End Sub
[COLOR=#333333]