vba在Internet Explorer中激活选项卡 [英] vba Activate a Tab in Internet Explorer

查看:287
本文介绍了vba在Internet Explorer中激活选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


使用以下代码:


   函数GetIE(sAddress As String)作为对象

    '找到一个带有匹配(部分)网址的IE窗口。 假设没有框架。

    '

        Dim objShell As Object,objShellWindows As Object,o As Object

        Dim retVal As Object,sURL As String

   

       设置retVal = Nothing

       设置objShell = CreateObject(" Shell.Application")

       设置objShellWindows = objShell.Windows

   

       对于每个o在objShellWindows

            sURL =""

            On Error Resume Next

            sURL = o.Document.Location

            On Error GoTo 0

           如果sURL<> ""然后

               如果sURL喜欢sAddress& " * QUOT;然后

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;设置retVal的= O

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;退出

               结束如果

           结束如果

       下一个o

   

       设置GetIE = retVal

   结束功能


我们可以找到加载了特定页面的现有IE实例。 

我们可以使用以下声明:


    公共声明函数SetForegroundWindow Lib" user32" (ByVal hwnd As Long)As Long


    私有声明功能ShowWindow Lib" user32" (ByVal hwnd As Long,ByVal nCmdShow As Long)As Long

    Private Const SW_SHOWNORMAL = 1

    Private Const SW_MAXIMIZE = 3

    Private Const SW_SHOW = 5

    Private Const SW_MINIMIZE = 6

    Private Const SW_RESTORE = 9


   私有声明函数IsIconic Lib" user32.dll" (ByVal hwnd As Long)使用以下代码作为长


,检查IE是否被最小化:


  ;&NBSP;&NBSP;如果CBool​​(IsIconic(IE.hwnd))那么    '如果窗口最小化...

        ShowWindow IE.hwnd,SW_RESTORE  '恢复窗口

   结束如果

    

并将IE窗口设置为焦点:


    SetForegroundWindow IE.hwnd'激活IE窗口


但是如果捕获的IE对象代表一个非活动选项卡,上面只带来IE主窗口聚焦 -
如何激活属于IE对象的Internet Explorer选项卡?


我到处寻找并且不能找到任何东西。 我们是否必须使用IAccessible对象?


提前致谢。


干杯zh
Rich

解决方案

Hi Rich,


感谢您在MSDN论坛上发帖。


由于您的问题与Excel对象模型无关,我会将您的主题移至
Visual Basic for Applications(VBA)
论坛以获得更好的支持。


感谢您的理解。


致以愉快的问候,


Hi,

Using code like this:

    Function GetIE(sAddress As String) As Object
    ' Find an IE window with a matching (partial) URL.  Assumes no frames.
    '
        Dim objShell As Object, objShellWindows As Object, o As Object
        Dim retVal As Object, sURL As String
   
        Set retVal = Nothing
        Set objShell = CreateObject("Shell.Application")
        Set objShellWindows = objShell.Windows
   
        For Each o In objShellWindows
            sURL = ""
            On Error Resume Next
            sURL = o.Document.Location
            On Error GoTo 0
            If sURL <> "" Then
                If sURL Like sAddress & "*" Then
                  Set retVal = o
                  Exit For
                End If
            End If
        Next o
   
        Set GetIE = retVal
    End Function

we can find an existing instance of IE with a certain page loaded. 
We can then use the following declarations:

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

    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Const SW_SHOWNORMAL = 1
    Private Const SW_MAXIMIZE = 3
    Private Const SW_SHOW = 5
    Private Const SW_MINIMIZE = 6
    Private Const SW_RESTORE = 9

    Private Declare Function IsIconic Lib "user32.dll" (ByVal hwnd As Long) As Long

with the following code, to check if IE is minimized:

    If CBool(IsIconic(IE.hwnd)) Then    'if window is minimized...
        ShowWindow IE.hwnd, SW_RESTORE  'restore the window
    End If
    
and set the IE window to be in focus:

    SetForegroundWindow IE.hwnd 'activeate the IE window

but if the captured IE object represents an inactive tab, the above only brings the IE main window into focus - how do I activate the internet explorer tab that belongs to the IE object?

I've looked everywhere and can't find anything.  Would we have to use an IAccessible object?

Thanks in advance.

Cheers
Rich

解决方案

Hi Rich,

Thank you for posting in the MSDN Forum.

Since your issue is not Excel Object Model related, I'll move your thread to Visual Basic for Applications (VBA) forum for better support.

Thank you for your understanding.

Best regards,


这篇关于vba在Internet Explorer中激活选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆