RE: Attempting to use VBA to Ping within Excel...
- From: urkec <urkec@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 22 Oct 2007 12:42:02 -0700
"Andy Dawkins" wrote:
Thank you urkec for your responce. I noticed that you mentioned that
Win32_PingStatus was added for windows XP. If I'm using Windows 2000 what
would I need to do to make it work?
I found that code here:
http://www.rlmueller.net/PingComputers.htm
You can find other two samples there, one uses WScript.Shell Exec method to
execute the Ping command and then checks it's output to determine if ping was
successful. The other uses WScript.Shell Run method. Both will work with
Windows 2000 (the first sample requires Windows Script Host 5.6, the other
WSH 5.1) If you use WshShell.Exec you won't be able to prevent Command Prompt
appearing on the screen, if you use WshShell.Run you will have to write the
Ping command output to a temporary txt file, so those are not ideal
solutions. The samples are VBScript, VBA the code would look something like
this:
Function Ping2(ByVal Host As String, _
ByVal Pings As Integer, ByVal TimeOut As Integer) As Boolean
Status = CreateObject("WScript.Shell"). _
Exec("%comspec% /c Ping -n " & CStr(Pings) & _
" -w " & CStr(TimeOut) & " " & Host).StdOut.ReadAll
'Debug.Print Status
If InStr(Status, "TTL=") = 0 Then
Ping2 = False
Else
Ping2 = True
End If
End Function
Then you can call Ping2 like this:
Ping2("ANAME", 1, 750)
--
urkec
.
- References:
- Attempting to use VBA to Ping within Excel...
- From: Andy Dawkins
- RE: Attempting to use VBA to Ping within Excel...
- From: Joel
- RE: Attempting to use VBA to Ping within Excel...
- From: Andy Dawkins
- RE: Attempting to use VBA to Ping within Excel...
- From: Joel
- RE: Attempting to use VBA to Ping within Excel...
- From: urkec
- RE: Attempting to use VBA to Ping within Excel...
- From: Andy Dawkins
- Attempting to use VBA to Ping within Excel...
- Prev by Date: RE: ISNA command in VBA
- Next by Date: Re: programatically deleted code still triggers macro warning
- Previous by thread: RE: Attempting to use VBA to Ping within Excel...
- Next by thread: Re: Range Usage
- Index(es):
Relevant Pages
|