Computing.Net > Forums > Programming > VBA Shell Function

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

VBA Shell Function

Reply to Message Icon

Original Message
Name: beaster
Date: July 31, 2002 at 03:38:19 Pacific
Subject: VBA Shell Function
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


Report Offensive Message For Removal


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

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



Report Offensive Follow Up For Removal

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

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.


Report Offensive Follow Up For Removal

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


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


Report Offensive Follow Up For Removal

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

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


Report Offensive Follow Up For Removal

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


Works a treat!!

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

Thanks a million!!


Report Offensive Follow Up For Removal







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








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software