Ping domains / Host

G

Ganesh

I have a Excel sheet (2007) with thousands of domain in one column and is
there anyway to get the next column saying that the perticular domain is
pinging or not?
 
T

Tim Williams

Try this.

Tim


'********************************************************
Sub Tester()
Debug.Print GoodDomain("www.google.com")
End Sub


Function GoodDomain(sdomain As String) As Boolean
Dim oShell As Object
Dim v

Set oShell = CreateObject("WScript.Shell")
Set v = oShell.Exec("ping " & sdomain & " -n 1")
GoodDomain = Not InStr(v.StdOut.ReadAll, "could not find host") > 0

End Function
'********************************************************
 
T

Tim Williams

What did you do ?
The function needs to be in a genral module, not in the sheet module...

Tim
 
G

Ganesh

the function is in the general module only.

Tim Williams said:
What did you do ?
The function needs to be in a genral module, not in the sheet module...

Tim
 
T

Tim Williams

Try this instead.
Tim

Option Explicit

Sub TestDomains()

Dim c As Range
Dim oShell As Object
Dim v

Set oShell = CreateObject("WScript.Shell")

For Each c In Selection.Cells
If c.Value <> "" Then
Set v = oShell.Exec("ping " & c.Value & " -n 1")
If InStr(v.StdOut.ReadAll, "could not find host") <> 0 Then
c.Offset(0, 1).Value = "Problem"
Else
c.Offset(0, 1).Value = "OK"
End If
End If
Next c

End Sub
 
G

Ganesh

Hey thanks Tim got the required output.... Can this made as the background
process as all most 1000 command windows are openning for the Excel i have?

Ganesh
 

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