Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Returning the IP results from a ping?

I snagged this beautiful piece of code from here, and I've seen other
code that could do it, but I'm having a hard time gluing it all
together. Is there any way I can make this:

---start code---

Public Sub PingIt()

Set Machines = Sheets(1).Range("A1", "A3")

For Each Machine In Machines.Cells
Debug.Print Machine
Set objPing = GetObject _
("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("select * from Win32_PingStatus " & _
"where address = '" & Machine & "'")

For Each objStatus In objPing

If objStatus.StatusCode = 0 Then
Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Success"


Else

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Failed"

End If

Next
Next

End Sub

---end code---

Not only tell me if it Success/Failed on the ping, but also in the
next column over the IP address?

TIA,
Benjamin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Returning the IP results from a ping?

" wrote:

I snagged this beautiful piece of code from here, and I've seen other
code that could do it, but I'm having a hard time gluing it all
together. Is there any way I can make this:

---start code---

Public Sub PingIt()

Set Machines = Sheets(1).Range("A1", "A3")

For Each Machine In Machines.Cells
Debug.Print Machine
Set objPing = GetObject _
("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("select * from Win32_PingStatus " & _
"where address = '" & Machine & "'")

For Each objStatus In objPing

If objStatus.StatusCode = 0 Then
Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Success"


Else

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Failed"

End If

Next
Next

End Sub

---end code---

Not only tell me if it Success/Failed on the ping, but also in the
next column over the IP address?

TIA,
Benjamin



Does this code work for you:

Public Sub PingIt()

Set Machines = Sheets(1).Range("A1", "A3")

For Each Machine In Machines.Cells
Debug.Print Machine
Set objPing = GetObject _
("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("select * from Win32_PingStatus " & _
"where address = '" & Machine & "'")

For Each objStatus In objPing

If objStatus.StatusCode = 0 Then

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Success"
Sheets(1).Cells(Machine.Row, Machine.Column + 2) = _
objStatus.ProtocolAddress

Else

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Failed"

End If

Next
Next

End Sub


I can't test it right now, but the documentation for ProtocolAddress says it
is the address that the destination used to reply.


--
urkec
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Returning the IP results from a ping?

On Mar 12, 3:18 pm, urkec wrote:
" wrote:
I snagged this beautiful piece of code from here, and I've seen other
code that could do it, but I'm having a hard time gluing it all
together. Is there any way I can make this:


---start code---


Public Sub PingIt()


Set Machines = Sheets(1).Range("A1", "A3")


For Each Machine In Machines.Cells
Debug.Print Machine
Set objPing = GetObject _
("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("select * from Win32_PingStatus " & _
"where address = '" & Machine & "'")


For Each objStatus In objPing


If objStatus.StatusCode = 0 Then
Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Success"


Else


Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Failed"


End If


Next
Next


End Sub


---end code---


Not only tell me if it Success/Failed on the ping, but also in the
next column over the IP address?


TIA,
Benjamin


Does this code work for you:

Public Sub PingIt()

Set Machines = Sheets(1).Range("A1", "A3")

For Each Machine In Machines.Cells
Debug.Print Machine
Set objPing = GetObject _
("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("select * from Win32_PingStatus " & _
"where address = '" & Machine & "'")

For Each objStatus In objPing

If objStatus.StatusCode = 0 Then

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Success"
Sheets(1).Cells(Machine.Row, Machine.Column + 2) = _
objStatus.ProtocolAddress

Else

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Failed"

End If

Next
Next

End Sub

I can't test it right now, but the documentation for ProtocolAddress says it
is the address that the destination used to reply.

--
urkec


It does. I love you. I love you. I love you. Where are you guys
getting the documentation from? (I saw a reference to it earlier)
Inside the help files under VBA?

Thank you so much urkec! ;)
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Returning the IP results from a ping?

" wrote:

On Mar 12, 3:18 pm, urkec wrote:
" wrote:
I snagged this beautiful piece of code from here, and I've seen other
code that could do it, but I'm having a hard time gluing it all
together. Is there any way I can make this:


---start code---


Public Sub PingIt()


Set Machines = Sheets(1).Range("A1", "A3")


For Each Machine In Machines.Cells
Debug.Print Machine
Set objPing = GetObject _
("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("select * from Win32_PingStatus " & _
"where address = '" & Machine & "'")


For Each objStatus In objPing


If objStatus.StatusCode = 0 Then
Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Success"


Else


Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Failed"


End If


Next
Next


End Sub


---end code---


Not only tell me if it Success/Failed on the ping, but also in the
next column over the IP address?


TIA,
Benjamin


Does this code work for you:

Public Sub PingIt()

Set Machines = Sheets(1).Range("A1", "A3")

For Each Machine In Machines.Cells
Debug.Print Machine
Set objPing = GetObject _
("winmgmts:{impersonationLevel=impersonate}"). _
ExecQuery("select * from Win32_PingStatus " & _
"where address = '" & Machine & "'")

For Each objStatus In objPing

If objStatus.StatusCode = 0 Then

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Success"
Sheets(1).Cells(Machine.Row, Machine.Column + 2) = _
objStatus.ProtocolAddress

Else

Sheets(1).Cells(Machine.Row, Machine.Column + 1) = _
"Failed"

End If

Next
Next

End Sub

Where are you guys
getting the documentation from? (I saw a reference to it earlier)
Inside the help files under VBA?


For WMI classes like Win32_PingStatus, it is he


http://msdn2.microsoft.com/en-us/lib...84(VS.85).aspx

--
urkec
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VLOOKUP not returning results Chris Kellock Excel Worksheet Functions 14 March 19th 08 08:30 AM
Vlookup Returning Same Results on Each Row tlatta Excel Discussion (Misc queries) 0 December 14th 05 07:34 PM
Vlookup Returning Same Results on Each Row Kleev Excel Discussion (Misc queries) 0 December 14th 05 07:33 PM
Ping results into Excel RB Smissaert Excel Programming 0 February 24th 05 03:00 PM
Returning VBA results to a cell JasonSelf[_2_] Excel Programming 2 January 24th 04 05:28 PM


All times are GMT +1. The time now is 01:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"