假设我有下面的代码片段:激活后台标签页在Internet Explorer中使用VBA
Option Explicit
Sub Main()
Dim IE As Object
Set IE = GetIE("http://www.google.com")
' Need tabbed page for google.com to come to the foreground
End Sub
的GetIE
功能下面参考
Function GetIE(sLocation As String) As Object
Dim objShell As Object, objShellWindows As Object, o As Object
Dim sURL As String
Dim retVal As Object
Set retVal = Nothing
Set objShell = CreateObject("shell.application")
Set objShellWindows = objShell.Windows
For Each o In objShellWindows
sURL = ""
On Error Resume Next
'check the URL and if it's the one you want then
'assign it to the return value and exit the loop
sURL = o.document.location
On Error GoTo 0
If sURL Like sLocation & "*" Then
Set retVal = o
Exit For
End If
Next o
Set GetIE = retVal
End Function
随着我使用GetObject
而不是CreateObject
我可能会遇到这样的情况,即我的对象实际上是Internet Explorer应用程序中的一个选项卡。
这个问题是出于我的自动化目的,我通常在任何时候都打开相当多的选项卡。我将如何去使IE对象带标签页www.google.com
到前台(使其成为可见标签)?我试过IE.Activate
,IE.Visible = True
,IE.Document.Focus
,并且无法获得我需要的结果。
我还应该补充一点,我可以用我需要的任何其他方式来操作选项卡(IE.Navigate
以及使用getElementByID
的挂钩元素),而不必将它作为Internet Explorer应用程序中的可见选项卡。
我对设置对象没有任何问题,我只需要知道如何激活IE浏览器中的选项卡并将其设置为活动窗口。因此,如果我自动化的标签位于后台,我将如何将它带到前台并在浏览器中显示标签的内容? –