ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SHELL command (https://www.excelbanter.com/excel-programming/279841-shell-command.html)

Robin Clay[_3_]

SHELL command
 
Greetings !

Regarding -

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

...which works just FINE in a DOS window, but not in VB
[RunTime error 53: File not found]

Can SKS please suggest -

(a) why it doesn't work

(b) what it should be, in order to work; and/or

(c) a better way of achieving the same thing?

RClay AT haswell DOT com

Chip Pearson

SHELL command
 
Robin,

Put the DOS Dir command in a bat file and call that bat file from Shell.
E.g,

Shell "C:\Test.bat",1


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Robin Clay" wrote in message
...
Greetings !

Regarding -

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

..which works just FINE in a DOS window, but not in VB
[RunTime error 53: File not found]

Can SKS please suggest -

(a) why it doesn't work

(b) what it should be, in order to work; and/or

(c) a better way of achieving the same thing?

RClay AT haswell DOT com




jaf

SHELL command
 
Hi Robin,
Chip's solution will work as always.
I'd point out the reason your shell failed is that redirection requires
invoking the command processor.
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.
Shell Environ("comspec") & " /k ping """ & strIP & """ """ & strFile &
"""", vbNormalFocus


--

John

johnf202 at hotmail dot com


"Robin Clay" wrote in message
...
Greetings !

Regarding -

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

..which works just FINE in a DOS window, but not in VB
[RunTime error 53: File not found]

Can SKS please suggest -

(a) why it doesn't work

(b) what it should be, in order to work; and/or

(c) a better way of achieving the same thing?

RClay AT haswell DOT com




Robin Clay[_3_]

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


All times are GMT +1. The time now is 02:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com