Can't download file via Webdav for Excel 2013 in VBA

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]
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,187,106
Messages
5,961,626
Members
438,556
Latest member
darrylburge

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top