Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving the output of a dos command throung Excel VBA 2

Status
Not open for further replies.

LSIGuy

MIS
Jun 26, 2002
18
US
Can someone please give me a pointer on how to save the output of a shell command issued through Excel VBA to a dump file? I need to be able to analyze the return to continue my program. Thanks.
 
Add a the redirect output symbol to your shell string



I.E.


shell("dir c:\temp >c:\temp\my_temp.txt")

you can then open the my_temp.txt in notepad or msdos edit, word, etc

or open it from within vba...

open ("c:\temp\my_temp.txt") for input as #1

 
Ooops my bad

You'll have to write the redirect string to a batch file,


then shell the batch file


example:

Sub write_batch()
Open ("c:\temp\my_temp.bat") For Output As #1
Print #1, "dir c:\temp >c:\temp\my_temp2.txt"
Close
End Sub
---------------------------
Sub run_bat()
Shell ("c:\temp\my_temp.bat")
End Sub



 
Etid,

I seem to recall that you could use something like the following to carry out a DOS command directly from the SHELL command, w/o resorting to batch files:

Code:
Shell("command.com /C dir c:\temp >c:\temp\myTemp.txt")

Also, I have successfully used the following on my new Win 2000 Pro system:

Code:
Shell ("cmd.exe /C dir c:\temp >c:\temp\my_temp.txt")

Comments?

Regards,
Mike
 
This worked for me on win 2k ...


Shell ("cmd.exe /C dir c:\temp >c:\temp\my_temp.txt")


Thanks and a star, Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top