Q:

how to download a pdf.php file from web browser using excel vba

Hi I am trying to download a file named " view.pdf.php file from web browser and save it as pdf file.(file is obtained while clicking on print icon in web browser, it opens a .pdf.php file in another browser)
Tried some samples from stack over flow but unable to get that downloaded in correct format.
Code tried: 
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
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 DownloadFile = True
End Function
Sub Test()
DownloadFile "https://app.goscripts.com/vendor/viewreferral.php?Id=XXXXX", "\\test\test.pdf"

End Sub

when trying to open the downloaded file it shows as " Adobe Acrobat Reader could not open'test.pdf' because it is either not a supported file type or because the file has been damaged" 
Please help me in fixing this error.

A:

Located an alternate method to save the file from web browser,
Code:
Const OLECMDEXECOPT_DODEFAULT = 0
Const OLECMDEXECOPT_PROMPTUSER = 1
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Const OLECMDEXECOPT_SHOWHELP = 3
Const OLECMDID_SAVEAS = 4
Const PRINT_WAITFORCOMPLETION = 2

Sub Sample()
Dim objIE, sh As Object
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Navigate "https://123.com/vendor/vieworder.pdf.php?OrderId=XXXX"
objIE.Visible = True
Do While objIE.ReadyState <> 4
DoEvents
Loop
objIE.ExecWB OLECMDID_SAVEAS, OLECMDEXECOPT_DODEFAULT
Set sh = CreateObject("WScript.Shell")
sh.AppActivate "Save AS"
Application.Wait (Now + TimeValue("00:00:02"))
sh.SendKeys "done", 1
sh.SendKeys ("{ENTER}")
objIE.Quit
End Sub

Thank for your support

