小编And*_*ndy的帖子

使用VBA代码Ping IP地址并在Excel中返回结果

我有一些可视基本代码(见下文),用于测试B列(excel电子表格中)的IP连接,并在c栏中显示它是否已连接或无法访问,我只是想知道你是否可以帮助我如果'连接',它希望它是绿色的,任何其他结果都是红色的.

此外,这个脚本可以每小时或每天自动运行吗?

非常感谢,安迪

Function GetPingResult(Host)

   Dim objPing As Object
   Dim objStatus As Object
   Dim strResult As String

   Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
       ExecQuery("Select * from Win32_PingStatus Where Address = '" & Host & "'")

   For Each objStatus In objPing
      Select Case objStatus.StatusCode
         Case 0: strResult = "Connected"
         Case 11001: strResult = "Buffer too small"
         Case 11002: strResult = "Destination net unreachable"
         Case 11003: strResult = "Destination host unreachable"
         Case 11004: strResult = "Destination protocol unreachable"
         Case 11005: strResult = "Destination …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

18
推荐指数
1
解决办法
6万
查看次数

标签 统计

excel ×1

excel-vba ×1

vba ×1