- 帖子
- 14
- 主題
- 2
- 精華
- 0
- 積分
- 50
- 點名
- 0
- 作業系統
- XP
- 軟體版本
- office 2003
- 閱讀權限
- 20
- 性別
- 男
- 來自
- 宜蘭
- 註冊時間
- 2013-8-26
- 最後登錄
- 2013-12-19
|
本帖最後由 linderlong 於 2013-8-28 08:59 編輯
回復 2# c_c_lai
感謝大大的指導!已可以使用,但速度上略為緩慢,不知有無方法提升測試的速度,程式如下:
假設a1至a10儲存格內容各為100.18.22.1至100.18.22.10,在我的電腦上執行完一次,要費時45秒,時間上太久了,不知如何縮短時程?謝謝!
Public Sub iptest()
Columns("B:B").Select
Selection.ClearContents
Range("A1").Select
費時 = Timer
i = 1
Do While Cells(i, 1) <> ""
Cells(i, 2) = Ping(Cells(i, 1))
i = i + 1
Loop
Cells(1, 3) = Timer - 費時
End Sub
Private Function Ping(strAddr As String) As String
Dim strTmpFile As String
strTmpFile = Environ("TEMP") & "\PingResult.txt" ' 準備建暫存檔在 Windows Temp 目錄下
CreateObject("WScript.Shell").Run Environ("COMSPEC") & " /c PING -n 1 " & strAddr & " > " & strTmpFile, 0, True
Ping = CreateObject("Scripting.FileSystemObject").OpenTextFile(strTmpFile).ReadAll
Ping = Replace(Ping, vbCrLf, "", 1)
On Error Resume Next
Kill strTm
End Function |
|