簡體   English   中英

將Internet Explorer窗口置於前台

[英]Bringing Internet Explorer window to foreground

我有一個打開Internet Explorer的宏

Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

后來,宏與其他窗口進行交互,因此IE失去了焦點。

但是,在其他交互之后,我需要將密鑰發送到IE應用程序。 我搜索了如何再次激活IE窗口,但是沒有一個起作用。

我嘗試過(1)

Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

Public Sub test()
  Set acObj = GetObject(, "InternetExplorer.Application")
  SetForegroundWindow acObj.hWndAccessApp
End Sub

(2)

Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

Public Sub test()
  Dim IE As Object
  Set IE = CreateObject("InternetExplorer.Application")
  'code
  SetForegroundWindow IE.hWndAccessApp
End Sub

(3)

IE.Focus 'or IE.Document.Focus

(4)

AppActivate("exactly_name_of_the_window")

這比任何東西更像是一個hack 基本上,您將其隱藏然后立即取消隱藏。

您可以嘗試以下Sub:

Sub ieBringToFront(ieObj As InternetExplorer) ' or (ieObj As Object) --> Late Binding

    With ieObj
        .Visible = False
        .Visible = True
    End With

End Sub

您可以像以下示例一樣使用它:

Sub Test()

    Dim ie As New InternetExplorer

    ' Addt'l Code

    ' IE Obj loses focus here

    ieBringToFront ie

End Sub

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM