Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I'm trying to write a macro that executes an external program that creates an excel file which I want to load into my qlikview application.
I have tried using the WScript.Shell.Execute command to do this and it seems to work, however the external program is prone to some delay which causes the loading to fail sometimes.
I would like to use the WScript.Shell.Run command instead which has the built in functionality of waiting for a return value, i.e:
set WsShell = CreateObject("WScript.Shell")
WsShell.Run <Path to external exe-file>,1,true
However when trying to execute the macro the execution always stops at the WsShell.Run line with no error message.
Is there any solution to this problem?
Best regards
Petter Grundström
The path respectively the complete statement must be in double-quotes wrapped. The correct syntax is really difficult and I couldn't never memorize it ... so I use most often trial and error ...
- Marcus
Most often the path isn't correct especially if there are any whitespace in, here an example:
set objWscript = CreateObject("WScript.Shell")
pdf = """C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe"""
objWscript.Run(pdf & """" & path & file & """")
Further it could be a lack of access rights within the filesystem for the user-account or the modul-security (left side of editor-window) isn't on external execution or user-settings within tab security isn't set.
- Marcus
Hi, thanks for your reply,
So, do I need to replace the whitespaces in the command path with "\ "?
The command path contains arguments to the exe-file as well i.e:
commandPath = "C:\Users\Petter\externalExe.exe\ argument1\ argument2\ argument3"
set WsShell = CreateObject("WScript.Shell")
WsShell.Run commandPath,1,true
//Petter
No - not replacing the whitespace else wrapped in with double-quotes:
""""Path\File"""" will be interpreted from compiler as "Path/File" (it's just syntax)
- Marcus
Hi,
I don't get it. This is the command I want to send:
C:\Users\Petter\executable.exe argument1 argument2 argument3
How should I write it for WsShell.Run to work?
Thanks for your help so far!
//Petter
I assume that your parameters caused this issue - have a look on this example:
running exe from vbscript and passing parameters
- Marcus
Well all that thread says is that I should write:
Set sh = CreateObject("WScript.Shell")
sh.Run "C:\Users\Petter\executable.exe argument1 argument2 argument3", 0, True
Which is exactly what I tried in the first place but the execution always stops at that line
Did you get this to work?
//Petter
Perhaps one of these parameters aren't valid for your exe - have you tried it without these parameters.
- Marcus
They are valid. I have written the exe myself and it works fine if i run it from command line with the exact same input, it also works if I run:
CreateObject("WScript.Shell").Exec( "C:\Users\Petter\executable.exe argument1 argument2 argument3")
But since Exec() doesn't have any functionality for waiting for a reply from the execution it doesn't fulfill my needs.
Do you have a working example of VBS code where you use WsShell.Run with parameters?
//Petter
This runs and set a new variable-value:
set objWscript = CreateObject("WScript.Shell")
objWscript.run "D:\QlikView_Client\qv.exe /vupdate=1 D:\MyApp.qvw"
- Marcus