|
如题: 有VBA 的excel文件在关闭的情况下自动又打开是什么问题?怎么解决?
附上代码:
Public RunWhen As String
'每1200秒执行一次
Public Const cRunIntervalSeconds = 1200
Public Const cRunWhat = "status_check"
Sub StartTimer()
RunWhen = Application.WorksheetFunction.Text(cRunIntervalSeconds / 86400, "[hh]:mm:ss")
Application.OnTime EarliestTime:=Now() + TimeValue(RunWhen), Procedure:=cRunWhat, Schedule:=True
End Sub
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 port unreachable"
Case 11006: strResult = "No resources"
Case 11007: strResult = "Bad option"
Case 11008: strResult = "Hardware error"
Case 11009: strResult = "Packet too big"
Case 11010: strResult = "Request timed out"
Case 11011: strResult = "Bad request"
Case 11012: strResult = "Bad route"
Case 11013: strResult = "Time-To-Live (TTL) expired transit"
Case 11014: strResult = "Time-To-Live (TTL) expired reassembly"
Case 11015: strResult = "Parameter problem"
Case 11016: strResult = "Source quench"
Case 11017: strResult = "Option too big"
Case 11018: strResult = "Bad destination"
Case 11032: strResult = "Negotiating IPSEC"
Case 11050: strResult = "General failure"
Case Else: strResult = "Unknown host"
End Select
If strResult = "Connected" Then
GetPingResult = "通"
Else
GetPingResult = "不通"
End If
Next
Set objPing = Nothing
End Function
Sub status_check()
Dim arData As Variant
arData = Sheet8.Range("A1").CurrentRegion
For i = 2 To UBound(arData)
arData(i, 3) = GetPingResult(arData(i, 2))
arData(i, 4) = Now()
DoEvents
Next
Sheet8.Range("A1").Resize(UBound(arData), UBound(arData, 2)) = arData
Call StartTimer
End Sub
|
|