Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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



  #3   Report Post  
Posted to microsoft.public.excel.programming
jaf jaf is offline
external usenet poster
 
Posts: 300
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
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
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
How to use the "shell" command? Tom Excel Discussion (Misc queries) 11 April 27th 10 12:52 AM
How can you wait for the SHELL command to terminate ? Dave Peterson[_3_] Excel Programming 1 October 1st 03 09:10 AM
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
Copying a file with VBA (or with a SHELL command) Franck V. Excel Programming 1 September 15th 03 07:46 PM


All times are GMT +1. The time now is 04:32 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"