Run a vbs file from MS-Excel

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using Office 2003 and Windows XP;

I am using the following code line to run a VBScript file:

Shell "MyPath\MyScript.vbs"

But, I get error: Invalid procedure call or argument

Any idea how I can get this to run using Shell?

The path and file are correct since I can run it using the hyperlink method,
but this produces an undesired unsupressable warning.

Thanks in advance.
 
Thanks for posting, using your suggestion no longer generates an error, but
the script fails to execute. I added a message box to first line in the
script file and it never fires.

Any other ideas?
 
I tested it with a simple vbs script file that shows a message box and it
worked. Maybe try providing the full path to the script. Or in a command
prompt, go to the directory where the script is and type in

cscript Myscript.vbs

If you try to execute it from the command prompt does it work? I guess you
can also try using wscript just in case that makes a difference..

Maybe also check the version of cscript.exe and wscript.exe. I have v5.6
for both. Both files should be in the C:\windows\system32 folder.
 
Vergel,

Thanks again my version of both files is: 5.6.0.8820

I changed it to:
Shell "C:\windows\system32\WScript.exe MyPath\MyScript.vbs"

As you suggested and now I know what is wrong...there are spaces in MyPath
(a variable); the spaces are required as they are at network level; do you
know how to get around this?

Thanks a lot for your help...
 
Hi Vergel,

Experimenting with it, this is what finally worked:

Shell "WScript " & """MyPath\MyScript.vbs"""

Thanks again so much for your assistance; could not have cracked it without
your help!
 
I found that enclosing the path and filename in double quotes works.. This
worked for me

Shell "cscript ""C:\a folder with spaces\test.vbs"""

So I guess if Mypath is a variable, you'll need to concatenate it with the
strings to formulate the cscript command. I think something like this would
work for you

Shell "cscript """ & MyPath & "\MyScript.vbs"""
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top