I am using Visual Basic for Applications (Excel) to validate an IP Host is live before attempting any network related functions.

(Im a new programmer, so please bare with me :) )
I would prefer to use the shell function to run ping and redirect the output to a text file.
when I have attempted to this.
1. the ping command runs fine.
2. it does not write out to a text file... here is my code:

Private Sub CommandButton1_Click()
 IP = ""
 PING = COMND & " " & IP
 bla = shell(PING)
End Sub

Another method I tried with the shell function was to call a batch file.
The Batch file contains the following code:


When ran from a command prompt this batch file works...however, if I try using the shell function as follows....

bla = shell("c:\pingip.bat")

It does not run the batch file.

any help on this would be greatly appreciated.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi bitshredder:
>  PING = COMND & " " & IP
This will cause the PING variable to have PING -N 1 > C:\TEXT.TXT
which is not what you want!

> bla = shell("c:\pingip.bat")
Shell works differently depending on the operating system you are on.
What is your OS?

Seems the option is case sensitive. On my system (XP) this only worked with lower case -n

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Dabas is correct try:

Private Sub CommandButton1_Click()
 IP = ""
 COMND = "ping -n 1 " & IP & " > C:\TEST.TXT"
 bla = shell(COMND)
End Sub

Here is a link to an open source control that will send and receive messages to and from command based applications such as ping.exe. The below link has all the source, to the redirect dll, and an example of how to use it in Visual Basic 6. This is easy to use, and is a really great open source project. Using this, it will do EXACTLY what you need to do (and more). Check it out, you wont be sorry. (the example will put the data you want into text boxes, or any other type of control you wish)



P.S. This control is a great way to give old dos programs like IPConfig, Ping, and TraceRT a grafical user interface.
bitshredderAuthor Commented:
okay cool Dabas was right on the first try,
It ended up being a captial 'N' for the ping parameter, when it should have been a lowercase 'n'.
thanks for the help in correcting me on this. 8รพ
-rich ;-)
I understand this is your first post.
I suggest you close the question by accepting the post with the answer.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.