I am using the below code to download an excel file from a url. The URL (which I can not share here) is for a ticketing system. I used the search button in the website to get all open and in progress tickets. After that there is a Export drop down button and from the drop down I selected Excel. The url I used is the code is the url of this Export to Excel button.
The code is exporting the excel file to given path, but there is only the page header and footer data to show the time of download and two lines saying "Displaying 0 issues at 07/Jul/14 3:14 PM." and "No Issues Found". in the file.
If I use the url directly on any website, it opens the file with data. If I use Workbooks.open "myUrl" same blank file is opening.
Can anyone please check what is wrong?
Sub downloadFile()
Test = Dir("C:\Users\" & Environ("username") & "\" & "SearchResult.xls")
If Not Test = "" Then
Kill ("C:\Users\" & Environ("username") & "\" & "SearchResult.xls")
End If
mylink = ""
myresult = 0
mylink = "http://mylink.com/issueviews:SearchResult-excel-all-fields/temp/SearchResult.xls?jqlQuery=status+in+%28Open%2C+%22In+Progress%22%29&tempMax=1000"
myresult = URLDownloadToFile(0, mylink, "C:\Users\" & Environ("username") & "\" & "SearchResult.xls", 0, 0)
If myresult <> 0 Then
MsgBox "Error downloading " & mylink & Chr(10) & Error(myresult)
Else
MsgBox "File has been downloaded"
End If
End Sub