Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7553305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:00:48+00:00 2026-05-30T11:00:48+00:00

I have the code below which works fine, steps through the rows pinging each

  • 0

I have the code below which works fine, steps through the rows pinging each host and updating the sheet.

Sub Do_ping()
  Set output = ActiveWorkbook.Worksheets(1)
  With ActiveWorkbook.Worksheets(1)
  Set pinger = CreateObject("WScript.Shell")

  pings = 1
  pingend = "FALSE"

 output.Cells(2, 4) = pings
 output.Cells(2, 5) = pingend

  Do

  Row = 2

  Do
   If .Cells(Row, 1) <> "" Then
    result = pinger.Run("%comspec% /c ping.exe -n 1 -w 250 " _
        & output.Cells(Row, 1).Value & " | find ""TTL="" > nul 2>&1", 0, True)

    If (result = 0) = True Then
     result = "TRUE"
    Else
     result = "FALSE"
    End If

    '  result = IsConnectible(.Cells(Row, 1), 1, 1000)
    output.Cells(Row, 2) = result        

   End If
   Row = Row + 1
  Loop Until .Cells(Row, 1) = ""

  waitTime = 1
  Start = Timer
  While Timer < Start + waitTime
   DoEvents
  Wend


 output.Cells(2, 4) = pings
 output.Cells(2, 5) = pingend

 pings = pings + 1

 Loop Until pingend = "TRUE"

  End With



End Sub

But suppose I have 50 devices and 40 of them are down. Because it is sequential I have to wait for the pings to time out on these devices and so a single pass can take a long time.

Can I in VBA create an object that I can create multiply instances of, each pinging a separate host, and then simple cycle though the objects pulling back a true/false property from them.

I don’t know how possible this is or how you deal with classes in VBA.

I want some thing like

set newhostping = newobject(pinger) 
pinger.hostname = x.x.x.x

to set up the object then object would have the logic

do
ping host x.x.x.x
if success then outcome = TRUE
if not success then outcome = FALSE
wait 1 second
loop

so back in the main code I could just use

x = pinger.outcome 

to give me the current state of the host, with out needing to wait for the current ping operation to complete. It would just return the result of the last completed attempt

Does any one have any code or ideas they could share?

Thank you

DevilWAH

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:00:49+00:00Added an answer on May 30, 2026 at 11:00 am

    You could use the ShellAndWait function below to run those calls asynchronously (i.e. in parallel). See my example with a simple tracert command which generally takes a few seconds to run. It opens 50 command windows running at the same time.

    Option Explicit
    
    Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
              ByVal dwProcessId As Long) As Long
    
    Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    
    Private Const STATUS_PENDING = &H103&
    Private Const PROCESS_QUERY_INFORMATION = &H400
    
    Public Sub test()
    
        Dim i As Long
        For i = 1 To 50
            ShellandWait "tracert www.google.com", vbNormalFocus, 1
        Next i
    
    End Sub
    
    Public Function ShellandWait(parProgramName As String, Optional parWindowStyle As VbAppWinStyle = vbMinimizedNoFocus, _
                Optional parTimeOutValue As Long = 0) As Boolean
    'source: http://www.freevbcode.com/ShowCode.Asp?ID=99
    'Time out value in seconds
    'Returns true if the program closes before timeout
    
      Dim lInst As Long
      Dim lStart As Long
      Dim lTimeToQuit As Long
      Dim sExeName As String
      Dim lProcessId As Long
      Dim lExitCode As Long
      Dim bPastMidnight As Boolean
    
      On Error GoTo ErrorHandler
    
      lStart = CLng(Timer)
      sExeName = parProgramName
    
      'Deal with timeout being reset at Midnight
      If parTimeOutValue > 0 Then
        If lStart + parTimeOutValue < 86400 Then
          lTimeToQuit = lStart + parTimeOutValue
        Else
          lTimeToQuit = (lStart - 86400) + parTimeOutValue
          bPastMidnight = True
        End If
      End If
    
      lInst = Shell(sExeName, parWindowStyle)
    
      lProcessId = OpenProcess(PROCESS_QUERY_INFORMATION, False, lInst)
    
      Do
        Call GetExitCodeProcess(lProcessId, lExitCode)
        DoEvents
        If parTimeOutValue And Timer > lTimeToQuit Then
          If bPastMidnight Then
            If Timer < lStart Then Exit Do
          Else
            Exit Do
          End If
        End If
      Loop While lExitCode = STATUS_PENDING
    
      If lExitCode = STATUS_PENDING Then
        ShellandWait = False
      Else
        ShellandWait = True
      End If
      Exit Function
    
    ErrorHandler:
      ShellandWait = False
    
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the code below, which works fine it can be viewed for an
I have this code below which works fine but seems unnecessary as it loops
I have the code below which works fine, but if I leave the text
So, I have the code below which works fine when entered into Google's Rich
I have a sample code snippet below which works just fine (I trimmed the
So far i have got the code below which works lovely when trying an
I have the following code which works just fine when the method is POST,
I am using PHP 5.3.6 I have the following code below. Everything works fine
I have the below SQL which works just fine: SELECT Message, CreateDate, AccountId, AlertTypeId
I have the following code which works fine however historically and again now I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.