Ping IP Address with VBA code and return results in Excel

前端 未结 2 1220
名媛妹妹
名媛妹妹 2020-12-01 03:18

I have some visual basic code (see below) that tests an IP connection in column B (of an excel spreadsheet) and puts whether or not it is connected or un-reachable in column

2条回答
  •  自闭症患者
    2020-12-01 03:51

    To have this run automatically at certain intervals, check out this link.

    Here's the relevant code:

    Public dTime As Date
    Dim lNum As Long
    
    Sub RunOnTime()
        dTime = Now + TimeSerial(0, 0, 10) 'Change this to set your interval
        Application.OnTime dTime, "RunOnTime"
    
        lNum = lNum + 1
        If lNum = 3 Then
            Run "CancelOnTime" 'You could probably omit an end time, but I think the program would eventually crash
        Else
            MsgBox lNum
        End If
    
    End Sub
    
    Sub CancelOnTime()
        Application.OnTime dTime, "RunOnTime", , False
    End Sub
    

    I would recommend including a ThisWorkbook.Save line as I can't speak to how long this will run without crashing, and I would imagine you could see problems if you left it for days at a time.

提交回复
热议问题