I am trying to create a vbscript snippet that can be launched from the command line or by double clicking the file in windows explorer. I need the script to find the current instance of IE and reload the page.
I found that since IE doesn’t write to the ROT table, I can’t use GetObject. I found a workaround but I’m stumped on the refresh page bit.
Here’s what I have so far:
set shellApp = createobject("shell.application")
for each window in shellApp.Windows
tname = typename(window.document)
if tname = "HTMLDocument" Then
'Reload here
end if
Next
I have tried this to reload the page but it didn’t work:
Here’s a variation of a script I put together for Experts-Exchange last week. As written it will refresh all open instances of IE. You can uncomment the commented lines if you want to specify a particular window title or URL.
'strTargetTitle = "Google"
'strTargetURL = "http://www.google.com"
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
If objShellWindows.Count = 0 Then
Wscript.Quit
End If
For i = 0 to objShellWindows.Count - 1
Set objIE = objShellWindows.Item(i)
'strTitle = objIE.Application.Document.Title
'strURL = objIE.LocationURL
'If InStr(strTitle, strTargetTitle) Then
objIE.Refresh
'End If
'If InStr(strURL, strTargetURL) Then
'objIE.Refresh
'End If
Next
That is great! I never thought about using the index.
Would you know how to interact with elements on the page? If I have the name or id of a control, how do I click the button, fill in the text box, etc.?
I think that a bright guy in my department was able to figure out some way of doing this - to access the Document object model of an IE window - which then would let you use document.findcontrolByID() or something like that to access the page.
I don’t think he was working in vbs though, so the techniques might not carry over. He could have been using API calls in vb6. I can ask him tomorrow.