ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Need Help Modifying Code (https://www.excelbanter.com/excel-programming/288356-need-help-modifying-code.html)

JStone0218

Need Help Modifying Code
 
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

beeawwb[_5_]

Need Help Modifying Code
 
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

--
Message posted from http://www.ExcelForum.com


BrianB

Need Help Modifying Code
 
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
'--------------------------------------------------



(JStone0218) wrote in message ...
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



All times are GMT +1. The time now is 02:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com