如何使用VB脚本刷新IE上的所有网页? [英] How to refresh all webpages on IE by using VB script?
问题描述
我正在尝试使用vb脚本在IE上打开几个不同的网站,他们将每隔10秒刷新一次所有网页。但现在我有这个代码,它只能刷新第一个网页,第二个网站根本不刷新。你能帮忙吗?非常感谢。
I'm trying to use vb script to open several different websites on IE and they will refresh all web pages in every 10 seconds. but now i have this codes, it only can refresh the first web, the second web doesn't refresh at all. Could you help with this? Thanks a lot.
Set objExplorer = CreateObject("InternetExplorer.Application")
WebSite ="http://keono.com/"
with objExplorer
.Navigate2 WebSite
.AddressBar = 1
.Visible = 1
.ToolBar = 1
.StatusBar = 1
end with
WebSite = "http://enquotemarketing.com/"
with objExplorer
.Navigate2 WebSite, &h800
.AddressBar = 1
.Visible = 1
.ToolBar = 1
.StatusBar = 1
end with
Do While True
WScript.Sleep 10000 ' 10 seconds
objExplorer.Refresh()
Loop
推荐答案
我的理解是你试图在不同的IE标签中打开网页,然后刷新它们。通过 .Navigate2 URL打开的新标签,& h800
是在一个单独的全新IE实例中创建的,但由于新标签属于IE窗口,因此它具有与IE窗口。因此,在导航后,您可以检查具有相同HWND的每个资源管理器窗口,并将新创建的窗口存储到数组。然后刷新其中的每个IE窗口。以下是示例代码:
My understanding is you are trying to open webpages in different IE tabs and then refresh them. New tab opened via .Navigate2 URL, &h800
is created in a separate brand new IE instance, but since new tab belongs to the IE window, it has the same HWND as IE window. Thus after navigate you can check each explorer window having the same HWND and store new created window to array. Then refresh each IE window within it. Here is the example code:
Option Explicit
Dim aTabs, aURLs, oIE, lIEHwnd, i, j, oWnd
' Navigate URLs in tabs
aURLs = Array( _
"http://keono.com/", _
"http://enquotemarketing.com/", _
"http://stackoverflow.com/" _
)
ReDim aTabs(UBound(aURLs))
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True
lIEHwnd = oIE.Hwnd ' IE window HWND
For i = 0 To UBound(aURLs)
oIE.Navigate2 aURLs(i), &H800 ' Open the page in another IE instance
' Process until new IE instance is created
Do
j = 0
For Each oWnd In CreateObject("Shell.Application").Windows
If oWnd.Hwnd = lIEHwnd And Not (oWnd Is oIE) Then
j = j + 1
Set aTabs(i) = oWnd ' Assuming the last window
End If
Next
Loop Until j = i + 1
Next
oIE.Quit ' Close 1st empty tab
' Wait until all tabs are ready
For Each oIE In aTabs
Do While oIE.ReadyState < 3 Or oIE.Busy
WScript.Sleep 10
Loop
Next
' Refresh tabs
Do
WScript.Sleep 10000
For Each oIE In aTabs
oIE.Refresh
Next
Loop
这篇关于如何使用VB脚本刷新IE上的所有网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!