以下のコードを作成して、Web サーバー/アプリケーションが実行されているかどうかを確認し、結果をファイルに記録しました。これは、Excel VBA と FSO Scripting Runtime を使用して行いました。これを vbs スクリプト ファイルに変換して Windows サーバーで実行するか、Linux サーバーで実行できる別のファイルに変換したいと考えています。コードのどの部分も依存していません。私はVBAコードベースを使用していました。コピーを vbs テキスト ファイルにコピーして実行しようとしましたが、エラーが発生し続けました。これをExcel VBAの外で実行するにはどうすればよいですか?
Option Explicit
Public Sub IE_Check()
Dim i As Long
Dim g As Long
Dim x As Long
Dim IE As Object
Dim objElement As Object
Dim objElement2 As Object
Dim Colobj1 As Object
Dim Colobj2 As Object
Dim Colobj3 As Object
Dim FindText1 As String
Dim FindText2 As String
Dim FindText3 As String
Dim TTime As String
Dim fso As New FileSystemObject
' Declare a TextStream.
Dim stream As TextStream
' Create a TextStream.
Set stream = fso.OpenTextFile("C:\log.txt", 2, True)
TTime = Time
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "http://yahoo.com"
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
FindText1 = InStr(1, IE.Document.body.innerhtml, "Internet Explorer cannot display the webpage")
If FindText1 > 0 Then
stream.WriteLine ("Webserver_down;" & TTime)
GoTo webserver_down
End If
webserver_up:
Set Colobj2 = IE.Document.getElementsByTagName("input")
g = 0
While g < Colobj2.Length
If Colobj2(g).Name = "Uid" Then
Colobj2(g).Value = "test"
Else
If Colobj2(g).Type = "submit" Then
Set objElement = Colobj2(g)
End If
End If
g = g + 1
Wend
objElement.Click
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
FindText3 = InStr(1, IE.Document.body.innerhtml, "mstrWebAdmin")
If FindText3 > 0 Then
stream.WriteLine ("IServer_down;" & TTime)
Else
stream.WriteLine ("All_GOOD;" & TTime)
End If
webserver_down:
IE.Quit
' Clean up
Set IE = Nothing
Set objElement = Nothing
Set Colobj1 = Nothing
Set objElement2 = Nothing
Set Colobj2 = Nothing
Set Colobj3 = Nothing
stream.Close
End Sub