Need Help Modifying Code

J

JStone0218

I need help with the following code. I would like to ping an IP Address
(x.x.x.x) that is referenced to cell A1 in Sheet1.

Any help is appreciated.

Sub Ping()
Sheets.Add
Shell ("cmd /c ping -n 10 -l 1024 x.x.x.x > c:\ping.txt")
Application.Wait Now + TimeSerial(0, 0, 15)
End Sub
 
B

beeawwb

Hi there.

First, just wondering why you have code for Sheets. Add every time yo
call the Ping() function. Seems kind of unnessesary to me.

As for getting a Ping function to ping the IP address in Sheet1.A1
that I can do.

Sub Ping()
Shell ("cmd /c ping -n 10 -l 1024 " & [Sheet1!A1] & " > c:\ping.txt")
Application.Wait Now + TimeSerial(0, 0, 15)
End Sub

I took the liberty of removing the Sheet.Add, but feel free to put i
back in if you need it. This does work, just tested it, and it write
the results of the A1 ping in C:\ping.txt

Hope that helps.

-Bo
 
B

BrianB

I don't know if your ping command is correct, but this is the basic
VBA code (untested) :-

'----------------------------------------------------
Sub Ping()
Dim IPaddress As String
Dim CommandStr As String
'--------------------------
IPaddress = Worksheets("Sheet1").Range("A1").Value
CommandStr = "PING " & IPaddress & "~"
rsp = Shell("cmd", 1)
SendKeys CommandStr, True
End Sub
'--------------------------------------------------
 

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

Top