3
當我執行下面的代碼時,一個黑色的命令窗口打開,它將閃爍,直到所有設備ping通。我如何靜靜地運行它?無聲地在後臺ping
Sub PING()
Application.ScreenUpdating = False
Dim strTarget, strPingResult, strInput, wshShell, wshExec
With Sheets(1)
shlastrow = .Cells(Rows.Count, "B").End(x1up).Row
Set shrange = .Range("B3:B7" & shlastrow)
End With
For Each shCell In shrange
strInput = shCell.Text
If strInput <> "" Then
strTarget = strInput
setwshshell = CreateObject("wscript.shell")
Set wshExec = wshShell.exec("ping -n 2 -w 5 " & strTarget)
strPingResult = LCase(wshExec.stdout.readall)
If InStr(strPingResult, "reply from") Then
shCell.Offset(0, 1).Value = "Reachable"
shCell.Offset(0, 2).Value = "Time"
Else
shCell.Offset(0, 1).Value = "UnReachable"
shCell.Offset(0, 2).Value = "Reachable"
End If
End If
Next shCell
End Sub
嘗試使用'strPingResult =殼牌代碼( 「平-n 2 -w 5」 &strTarget,vbHide)' –
我可以在哪裏插入它,或者我需要替換某些東西。先生,我是vba新手。 –
替換你的'Set wshExec = wshShell.exec(「ping -n 2 -w 5」&strTarget)'並且'strPingResult = LCase(wshExec.stdout.readall)' –