假設我有下面的代碼片段:激活後臺標籤頁在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瀏覽器中的選項卡並將其設置爲活動窗口。因此,如果我自動化的標籤位於後臺,我將如何將它帶到前臺並在瀏覽器中顯示標籤的內容? –