简体   繁体   English

将Internet Explorer窗口置于前台

[英]Bringing Internet Explorer window to foreground

I have a macro that opens the Internet Explorer 我有一个打开Internet Explorer的宏

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

Later the macro interacts with other windows, so the IE loses the focus. 后来,宏与其他窗口进行交互,因此IE失去了焦点。

But, after the other interactions, I need to send keys to the IE application. 但是,在其他交互之后,我需要将密钥发送到IE应用程序。 I searched how to activate again the IE Window, but none worked. 我搜索了如何再次激活IE窗口,但是没有一个起作用。

I tried (1) 我尝试过(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) (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) (3)

IE.Focus 'or IE.Document.Focus

(4) (4)

AppActivate("exactly_name_of_the_window")

This is more of a hack than anything. 这比任何东西更像是一个hack Basically, you will hide it then immediately unhide it. 基本上,您将其隐藏然后立即取消隐藏。

You could try this Sub: 您可以尝试以下Sub:

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

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

End Sub

You would use it like this example: 您可以像以下示例一样使用它:

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