Thread: Ping via VBA
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Helmut Weber Helmut Weber is offline
external usenet poster
 
Posts: 15
Default Ping via VBA

Hi everybody,

I think, the OP will know by now about numbers and strings
and about how to build the command string for the shell.
Anyway, here is one more elaborate example.
Not the shortest or best way to do it, for sure,
it is just to make it all clear.

Sub MyPing()
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim y As Long
Dim z As Long
Dim MyCmd As String

a = "192."
b = "0."
For y = 0 To 255
c = CStr(y)
c = c & "."
For z = 0 To 255
d = CStr(z)
MyCmd = "cmd /c ping " & a & b & c & d & " c:\test\ping.txt"
' seems to work
MyCmd = "cmd /c ping 99.113.11.8 c:\test\ping.txt"
' for testing with an existing IP
' though I've changed the number for the posting ;-)
Shell (MyCmd)
Next z
Next y

End Sub

Like Vista Small Business it set up here,
it is not possible to write into the root directory c:\,
therefore I was writing to c:\test\...

Furthermore, the OP might have to wait until the
shell command has written the textfile.
Google for shellx, xshell, and others, like
http://vb.mvps.org/hardcore/html/usingshell.htm
http://vb.mvps.org/samples/project.asp?id=Shell32

For appending text to a textfile, use "".

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP