Computing.Net > Forums > Programming > VBA Shell Function

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VBA Shell Function

Reply to Message Icon

Name: beaster
Date: July 31, 2002 at 03:38:19 Pacific
Comment:

Can anyone tell me how to run an exe, with parameters (eg. C:\cmd.exe p1 3), in VBA for Excel 97. Up until now I've been putting the command into a batch file and using the shell function to run it.

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: Annar
Date: July 31, 2002 at 06:42:11 Pacific
Reply:

hi
Usally you can use the 'shell' function in ur code.
Just type Shell and the hit space then u'll see the explainations.
Anyway the shell command 'cmd' is a bit tricky. If u try to start a dos shell and then run a program within that shell, it doesnt work. The reason is that u only start the dos shell and it ends with that. the shell doesnt execute any other command.
example:
Shell "cmd.exe help",vbnormalfocus

this command will only start cmd and not anything else. The reason is that cmd and help are 2 programs. help is no option to cmd

I hope this isnt to unclear!

Annar



0

Response Number 2
Name: Annar
Date: July 31, 2002 at 06:54:33 Pacific
Reply:

Anyway
u can run the cmd with the /C option with the shell funtion that works
eg: Shell "cmd /C sol",vbhide
this line will start the solitaire game.


0

Response Number 3
Name: beaster
Date: July 31, 2002 at 07:00:37 Pacific
Reply:


Sorry -- only used cmd as a (bad) example -- the actual command is as follows.

cmdLine = "D:\program files\veritas\netbackup\bin\admincmd\bperror.exe -jobid 1223"
Where the jobid portion is the parameter. But when I try to
'Shell cmdLIne,1' - it returns with an invalid error.

Thanks


0

Response Number 4
Name: Annar
Date: July 31, 2002 at 07:36:30 Pacific
Reply:

hi
OK
I tried ur code on my computer just to see if i could get the same error. But the only error ive got was of course that it coulddnt find the file.
So the code is OK. but it does seem that its something to do with the program u try to start. IS it a windowsprogram? What does happen when u start it from the 'run' meny on a computer. Sometimes u need the put some quatation marks in ur code.
Eg "program files" and not program files. This means that u have to use the chr(34) function in ur code.

maybe!

Annar


0

Response Number 5
Name: beaster
Date: July 31, 2002 at 07:58:26 Pacific
Reply:


Works a treat!!

Had to put cmdLine = "cmd " + chr(34) + "d:\....." + chr(34)

Thanks a million!!


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VBA Shell Function

shell function www.computing.net/answers/programming/shell-function/15166.html

Access 2000 VBA search function www.computing.net/answers/programming/access-2000-vba-search-function/7020.html

VBA math function for time dilation www.computing.net/answers/programming/vba-math-function-for-time-dilation/6177.html