Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Shell Function - Execute DOS Command

Excel 2000 running in XP:

Having trouble getting consistent results from VBA Shell Function.

For example, this command appears to run okay, but doesn't print cat.txt,
which is located in root directory. Is there something wrong with syntax?
Thanks ....

ID = Shell("command.com /c print cat.txt")

bill morgan


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 175
Default Shell Function - Execute DOS Command

Can I suggest binning the use of shell? have a look at this link:

http://msdn.microsoft.com/library/de...ctPropMeth.asp

It's the Windows Script Host. It's much more user friendly that running
shell (la la la).


--
www.alignment-systems.com


"bill_morgan" wrote:

Excel 2000 running in XP:

Having trouble getting consistent results from VBA Shell Function.

For example, this command appears to run okay, but doesn't print cat.txt,
which is located in root directory. Is there something wrong with syntax?
Thanks ....

ID = Shell("command.com /c print cat.txt")

bill morgan


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Shell Function - Execute DOS Command

Would it work if you replaced the space in "print cat.txt" with say an
underscore. If so try embracing the string in the shell function with an
additional pair of quotes, perhaps chr(34) & "string" & chr(34)

Regards,
Peter T


"bill_morgan" wrote in message
...
Excel 2000 running in XP:

Having trouble getting consistent results from VBA Shell Function.

For example, this command appears to run okay, but doesn't print cat.txt,
which is located in root directory. Is there something wrong with syntax?
Thanks ....

ID = Shell("command.com /c print cat.txt")

bill morgan




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Shell Function - Execute DOS Command

I think function is working - just can't see the results. Command line opens
briefly in task bar and then closes, but no error is returned that I can see.

Function is returning a non-zero value. Underscore you suggested below also
works, but still cannot view results.

"Peter T" wrote:

Would it work if you replaced the space in "print cat.txt" with say an
underscore. If so try embracing the string in the shell function with an
additional pair of quotes, perhaps chr(34) & "string" & chr(34)

Regards,
Peter T


"bill_morgan" wrote in message
...
Excel 2000 running in XP:

Having trouble getting consistent results from VBA Shell Function.

For example, this command appears to run okay, but doesn't print cat.txt,
which is located in root directory. Is there something wrong with syntax?
Thanks ....

ID = Shell("command.com /c print cat.txt")

bill morgan





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Shell Function - Execute DOS Command

On my way to that site. Thanks for the suggestion.

"John.Greenan" wrote:

Can I suggest binning the use of shell? have a look at this link:

http://msdn.microsoft.com/library/de...ctPropMeth.asp

It's the Windows Script Host. It's much more user friendly that running
shell (la la la).


--
www.alignment-systems.com


"bill_morgan" wrote:

Excel 2000 running in XP:

Having trouble getting consistent results from VBA Shell Function.

For example, this command appears to run okay, but doesn't print cat.txt,
which is located in root directory. Is there something wrong with syntax?
Thanks ....

ID = Shell("command.com /c print cat.txt")

bill morgan




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Shell Function - Execute DOS Command

Here is what worked (simple oversight on my part):

Sub printer2()
m = Shell("command.com cd\")
t = Shell("command.com /c print cat.txt")
End Sub

OR

Sub print_stuff()
FileSystem.ChDir "c:\"
t = Shell("command.com /c print cat.txt")
End Sub



"Peter T" wrote:

Would it work if you replaced the space in "print cat.txt" with say an
underscore. If so try embracing the string in the shell function with an
additional pair of quotes, perhaps chr(34) & "string" & chr(34)

Regards,
Peter T


"bill_morgan" wrote in message
...
Excel 2000 running in XP:

Having trouble getting consistent results from VBA Shell Function.

For example, this command appears to run okay, but doesn't print cat.txt,
which is located in root directory. Is there something wrong with syntax?
Thanks ....

ID = Shell("command.com /c print cat.txt")

bill morgan





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Shell Function - Execute DOS Command

Thanks for the feedback

Afraid my original suggestion was a never going to be useful. Somehow I read
you wanted to print a file named "print cat.txt". Sorry if that lead you up
the wrong path!

But had that been the case, ie a space in the fullname, the extra quotes are
necessary with some usages of Shell.

Regards,
Peter T

"bill_morgan" wrote in message
...
Here is what worked (simple oversight on my part):

Sub printer2()
m = Shell("command.com cd\")
t = Shell("command.com /c print cat.txt")
End Sub

OR

Sub print_stuff()
FileSystem.ChDir "c:\"
t = Shell("command.com /c print cat.txt")
End Sub



"Peter T" wrote:

Would it work if you replaced the space in "print cat.txt" with say an
underscore. If so try embracing the string in the shell function with an
additional pair of quotes, perhaps chr(34) & "string" & chr(34)

Regards,
Peter T


"bill_morgan" wrote in message
...
Excel 2000 running in XP:

Having trouble getting consistent results from VBA Shell Function.

For example, this command appears to run okay, but doesn't print

cat.txt,
which is located in root directory. Is there something wrong with

syntax?
Thanks ....

ID = Shell("command.com /c print cat.txt")

bill morgan







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 Command JOHN Excel Programming 1 November 17th 04 10:39 AM
Winzip - Shell Execute FastOneBaz[_4_] Excel Programming 3 July 21st 04 04:16 PM
Shell command MAx Excel Programming 2 June 4th 04 04:11 PM
xp shell command using vba Sudhendra Excel Programming 2 February 16th 04 05:56 AM
SHELL command Robin Clay[_3_] Excel Programming 3 October 17th 03 02:50 PM


All times are GMT +1. The time now is 06:40 AM.

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"