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
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.
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)
Summary: Does anyone know how to close a file if it was opened using the shell function? Below is the code I currently have. 'opens file temp = Shell("C:\MSOFFICE\OFFICE11\msaccess.exe C:\Data\Encrypted\TA.md...
Summary: I'm trying to write a access 2000 VBA search function that accept user text input and return records based on case id or name found (as entered by user). Case id is the primary key for all records. Ca...
Summary: i am new to VBA and need a VBA program that i can call in excel. this program would solve an equation such as one of time dilation: t = t0/sqrt(1-(v/c)^2) i actually have to do this for a number of f...