Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 354
Default shell function

Hello,
I am trying to run this shell for the first time and have problems with the
syntax.
Can anybody help.

The situation is as follows:

executable file: aaa.exe located in e:\folder1

the way this program works in works on DOS is: aaa <input.inp output.out

what is the shell syntax that would do the same as DOS (see above)?
thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default shell function

From the help topics:

' Specifying 1 as the second argument opens the application in
' normal size and gives it the focus.
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1) ' Run Calculator.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 354
Default shell function

thanks,
however, I am not so good at this:

I tried your suggestion:
Dim RetVal
RetVal = Shell("e:\folder1\aaa.EXE", 1) ' Run Calculator.


and did not work



how do I run a shell command equivalent to this DOS command:
aaa<inp.inpout.out

could you take a look again
thanks



" wrote:

From the help topics:


' Specifying 1 as the second argument opens the application in
' normal size and gives it the focus.
Dim RetVal
RetVal = Shell("C:\WINDOWS\CALC.EXE", 1) ' Run Calculator.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default shell function

Give this a try (and don't forget to Dim the new variables, all of them As
String)...

ProgramFile = "e:\folder1\aaa.EXE"
InFile = "Inp.Inp"
OutFile = "Out.Out
Shell Environ("comspec") & " /c " & ProgramFile & " <" & InFile & " " &
OutFile, vbHide

Below is a short write-up I have posted in the past over in the compiled VB
newsgroups, but everything in it should apply to the VBA world without
change.

Rick

The following is a compilation of several posts I've given in the past
regarding the Shell command. Your question is addressed in there; the
remainder is for your consideration....

You can use the Shell command. To execute internal DOS command (Dir, Copy,
etc. as well as redirection of screen output), the command processor must be
specified (using the Environ$ function and "comspec" as its argument returns
the correct command processor path on NT and non-NT systems) . Specifying
the command processor is safe & generic and will work with non-internal
commands also. That syntax, using an XCopy command as an example is:

Shell Environ$("comspec") & " /c xcopy """ & _
Source & """ """ & Destination & """ " & Option, vbHide

You set the Source and Destination (string variables) to the appropriate
paths and the Option (string variable), if any, which can be found by
opening an MSDOS Prompt window and typing xcopy /?. (Note: You can type /?
after any DOS command at a DOS prompt to list the available options for that
command.) One more example would be to list all the files in a directory
including subdirectories and subdirectories of subdirectories and all of
their files.

CommandLine = "dir """ & FileSpec & _
""" /s/b """ & RedirectTo & """"
Shell Environ$("comspec") & " /c " & CommandLine, vbHide

Here, the output of a Dir command is redirected to a file-path you specify
in the RedirectTo (string variable). The /s/b are options to the Dir command
that tell it to recurse throught its subdirectories and not to include
header or summary information.

I used a variable for the file name so that I could more easily explain the
benefit of encasing it in quotemarks. If you redirect to a file that has
spaces in its name, or if there are spaces in the path specification itself,
then the filename *must* be quoted to protect the spaces from DOS's desire
to use them as delimiters. (That's what all those quotemarks in the Shell
statement are for.) If the filename doesn't have spaces in it, the quotes
aren't necessary BUT they don't hurt either. Hence, the above will work with
either.

As for your PING question, something like the following should work:

strIP = "4.17.23.1"
Shell Environ$("comspec") & " /c ping " & _
strIP & " """ & RedirectFile & """", vbHide

Although you didn't specify it in your original post, I assume you want to
use vbHide for the optional 2nd parameter to Shell. This hides the DOS
window so that your user doesn't see it. If you want the DOS window to
remain visible, you would use the vbNormalFocus BUT you must use a /k
instead of a /c for the command processor argument. Basically, the /c tells
the command processor "here comes a command and, when its finished
executing, close the DOS shell it is running in" whereas the /k also tells
the command processor that a command follows, but it instructs it to leave
the DOS session running.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 354
Default shell function


thanks, it worked,
just a little bit of work to make the path work, it did not wanted to run
with the xls file in a different directory, even if the VBA had the correct
path of the executable


"Rick Rothstein (MVP - VB)" wrote:

Give this a try (and don't forget to Dim the new variables, all of them As
String)...

ProgramFile = "e:\folder1\aaa.EXE"
InFile = "Inp.Inp"
OutFile = "Out.Out
Shell Environ("comspec") & " /c " & ProgramFile & " <" & InFile & " " &
OutFile, vbHide

Below is a short write-up I have posted in the past over in the compiled VB
newsgroups, but everything in it should apply to the VBA world without
change.

Rick

The following is a compilation of several posts I've given in the past
regarding the Shell command. Your question is addressed in there; the
remainder is for your consideration....

You can use the Shell command. To execute internal DOS command (Dir, Copy,
etc. as well as redirection of screen output), the command processor must be
specified (using the Environ$ function and "comspec" as its argument returns
the correct command processor path on NT and non-NT systems) . Specifying
the command processor is safe & generic and will work with non-internal
commands also. That syntax, using an XCopy command as an example is:

Shell Environ$("comspec") & " /c xcopy """ & _
Source & """ """ & Destination & """ " & Option, vbHide

You set the Source and Destination (string variables) to the appropriate
paths and the Option (string variable), if any, which can be found by
opening an MSDOS Prompt window and typing xcopy /?. (Note: You can type /?
after any DOS command at a DOS prompt to list the available options for that
command.) One more example would be to list all the files in a directory
including subdirectories and subdirectories of subdirectories and all of
their files.

CommandLine = "dir """ & FileSpec & _
""" /s/b """ & RedirectTo & """"
Shell Environ$("comspec") & " /c " & CommandLine, vbHide

Here, the output of a Dir command is redirected to a file-path you specify
in the RedirectTo (string variable). The /s/b are options to the Dir command
that tell it to recurse throught its subdirectories and not to include
header or summary information.

I used a variable for the file name so that I could more easily explain the
benefit of encasing it in quotemarks. If you redirect to a file that has
spaces in its name, or if there are spaces in the path specification itself,
then the filename *must* be quoted to protect the spaces from DOS's desire
to use them as delimiters. (That's what all those quotemarks in the Shell
statement are for.) If the filename doesn't have spaces in it, the quotes
aren't necessary BUT they don't hurt either. Hence, the above will work with
either.

As for your PING question, something like the following should work:

strIP = "4.17.23.1"
Shell Environ$("comspec") & " /c ping " & _
strIP & " """ & RedirectFile & """", vbHide

Although you didn't specify it in your original post, I assume you want to
use vbHide for the optional 2nd parameter to Shell. This hides the DOS
window so that your user doesn't see it. If you want the DOS window to
remain visible, you would use the vbNormalFocus BUT you must use a /k
instead of a /c for the command processor argument. Basically, the /c tells
the command processor "here comes a command and, when its finished
executing, close the DOS shell it is running in" whereas the /k also tells
the command processor that a command follows, but it instructs it to leave
the DOS session running.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell function Phil1982 Excel Programming 2 March 16th 06 12:39 AM
Shell function John Keturi Excel Programming 1 May 23rd 04 02:09 AM
Shell function II [email protected] Excel Programming 1 September 19th 03 05:55 PM
Shell function II Don Guillett[_4_] Excel Programming 1 September 19th 03 03:31 PM
Shell function David Excel Programming 0 September 19th 03 11:30 AM


All times are GMT +1. The time now is 07:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"