SHELL command

R

Robin Clay

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
 
C

Chip Pearson

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 (e-mail address removed)
 
J

jaf

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
 
R

Robin Clay

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
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Shell "mkdir" 2
Place a SHELL Window 3
Positioning a DOS Window 4
Icon 2
Duplicate ToolBar Buttons 6
VLOOKUP reference 1
Back Up 4
From Cell to InputBox 2

Top