楼主 chrisfang |
Q:如何使用程序测试网址是否可以ping通? A:可以参考以下VBA代码进行ping的测试:
有关使用VBA进行ping测试并在程序中返回ping程序运行结果的信息,可参见:http://www.exceltip.net/thread-6951-1-1.html |
2楼 xyh9999 |
十分有用,多谢楼主。 |
3楼 wise |
' VBA中通过Wscript.Shell对象Ping主机是否连接 Function sPing(sHost As String) As String Dim oFSO As Object, oShell As Object, oTempFile As Object Dim sLine As String, sFilename As String Set oFSO = CreateObject("Scripting.FileSystemObject") Set oShell = CreateObject("Wscript.Shell") sFilename = oFSO.GetTempName oShell.Run "cmd /c ping " & sHost & " >" & sFilename, 0, True Set oTempFile = oFSO.OpenTextFile(sFilename, 1) Do While oTempFile.AtEndOfStream <> True sLine = oTempFile.Readline sPing = sPing & Trim(sLine) Loop oTempFile.Close oFSO.DeleteFile (sFilename) End Function Sub TestPing() MsgBox sPing("www.exceltip.net") End Sub |