Thread: SHELL command
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Robin Clay[_3_] Robin Clay[_3_] is offline
external usenet poster
 
Posts: 55
Default SHELL command

Thank you both very much for your kind response to my plea

Put the DOS Dir command in a bat file
and call that bat file from Shell.
E.g, Shell "C:\Test.bat",1


Hmmm...
I had thought of that,
but thought there MUST be a better way !

Like this...
Shell(Environ$("comspec") & " /c dir C:\ /S
C:\DirList1.$$$",1)

Spaces in the path or filename have to be wrapped in

double quotes.

Blimey, that's complicated !

I think I'll stick to Chip's method after all !

Thus :-

Public Sub RunShell(myCommandLine, myWindowStyle)

' Write it to a batch file
Open "C:\RunShell.bat" for Output as #1
Print #1, myCommandLine
Close #1

' Run the batch file
Shell "C:\RunShell.bat", myWindowStyle

' Delete the batch file
Kill "C:\RunShell.bat"

End Sub

So instead of
Shell "dir C:\ /S C:\DirList1.$$$",1

I would use
RunShell "dir C:\ /S C:\DirList1.$$$", WindowStyle


Thanks again