Can this run quicker?

cbzdmh

Board Regular
Joined
Jul 16, 2007
Messages
58
I have a Macro that engages with the Shell to run ping commands, the only problem is that it opens a new command prompt window every time it loops, it's alright if it's only a dozen, but i'm thinking of scaling this up to 1000+

Is there anyway of keeping the one window open and still be able to use the StdOut

Here's my code:
It returns No if it won't ping and returns the i.p. address if it does. I've utilised the collective wisdom of the board on this one so please feel free to use the code.


Function WillItPing(PCToPing As String)
Pings = 1
timeout = 200

Status = CreateObject("WScript.Shell"). _
Exec("%comspec% /c Ping -n " & Pings & " -l 2" & " -w " & timeout & " " & PCToPing).StdOut.ReadAll

If InStr(Status, "TTL=") = 0 Then
'If no ping, return No
WillItPing = "No"
Else
'If it pings, get the I.P. Address
ip_start = InStr(1, Status, "Reply from ", vbTextCompare) + 11
ip_end = InStr(ip_start, Status, ":", vbTextCompare)
Ip_Length = ip_end - ip_start
WillItPing = Mid(Status, ip_start, Ip_Length)
End If

End Function
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
I don't know the answer to your specific question. However can't you close the window every time the function runs ? Kaps

Kaps
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,585
Members
448,972
Latest member
Shantanu2024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top