Internet explorer 在Visual Basic中将焦点设置为Internet Explorer对象

Internet explorer 在Visual Basic中将焦点设置为Internet Explorer对象,internet-explorer,vba,setfocus,Internet Explorer,Vba,Setfocus,有人知道如何使用Visual Basic将焦点设置到IE对象上吗?我尝试了myieobject.SetFocus,但编译器使用此语句时出错。set.Visible=True-如果您在弹出窗口中的某个位置丢失了屏幕,则必须循环浏览窗口标题以激活特定标题 Dim objShell As Shell Dim objIndex As InternetExplorer Set objShell = New Shell For Each objIndex In objShell.Windows

有人知道如何使用Visual Basic将焦点设置到IE对象上吗?我尝试了
myieobject.SetFocus
,但编译器使用此语句时出错。

set
.Visible=True
-如果您在弹出窗口中的某个位置丢失了屏幕,则必须循环浏览窗口标题以激活特定标题

Dim objShell As Shell
Dim objIndex As InternetExplorer

Set objShell = New Shell

For Each objIndex In objShell.Windows
    If TypeName(objIndex.Document) = "HTMLDocument" Then
        If InStr(objIndex.Document.Title, "Stack Overflow") > 0 Then
            objIndex.Visible = True
            Exit For
        End If
    End If
Next objIndex

以下是使用IE对象可以做的事情:

我需要一个电子表格,在执行一个功能后将焦点“设置”到Internet Explorer,这样我就不用费心点击它了。这就是我发现的工作:

      Const myPageTitle As String = "Title of my webpage"
      Const myPageURL As String = "http://www.mywebpage.com"
      Dim myIE As SHDocVw.InternetExplorer
      Dim myIE As InternetExplorer
      Set myIE = GetOpenIEByTitle(myPageTitle, False)


      myIE.visible = false
      DoEvents
      myIE.visible = true  
     'for some reason, making the page invisible then visible always ensures it pops up

    Function GetOpenIEByTitle(i_Title As String, _
                          Optional ByVal i_ExactMatch As Boolean = True) As SHDocVw.InternetExplorer
Dim objShellWindows As New SHDocVw.ShellWindows

  If i_ExactMatch = False Then i_Title = "*" & i_Title & "*"
  'ignore errors when accessing the document property
  On Error Resume Next
  'loop over all Shell-Windows
  For Each GetOpenIEByTitle In objShellWindows
    'if the document is of type HTMLDocument, it is an IE window
    If TypeName(GetOpenIEByTitle.document) = "HTMLDocument" Then
      'check the title
      If GetOpenIEByTitle.document.Title Like i_Title Then
        'leave, we found the right window
        Exit Function
      End If
    End If
  Next
End Function

试试这个。通过shell命令打开internetexplorer,您可以在其中定义焦点(这是焦点窗口和小窗口),然后捕获shell/explorer窗口并将其定义为internetexplorer对象。也许有比睡觉更好的方法等待

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub call_IE()
Dim IE As InternetExplorer
Dim htmldoc As HTMLDocument

Set IE = Open_Focused_explorer()
IE.Navigate "google.com"
Set htmldoc = IE.Document

End Sub

Function Open_Focused_explorer() As InternetExplorer
Dim shellWins As ShellWindows

'if windows are 64bit IE is on diferent location
#If Win64 Then
     Shell "C:\Program Files (x86)\Internet Explorer\iexplore.exe", vbNormalFocus
#Else
    Shell "C:\Program Files\Internet Explorer\iexplore.exe", vbNormalFocus
#End If


 'wait until explorer is full loaded
 Sleep 4000

 On Error Resume Next
    'create collection of all explorers
  Set shellWins = New ShellWindows

    If shellWins.Count > 0 Then
        ' Get last one
        Set Open_Focused_explorer = shellWins.Item(shellWins.Count - 1)
    End If
On Error GoTo 0

End Function
试试这个:

'First, hide the object even if it's visible
myieobject.Visible = False
' Second, show the object to focusing
myieobject.Visible = True

你和IE的关系怎么样?你能给我们看一些代码吗?还有,聚焦IE背后的意图是什么?您正在尝试更新任何字段吗?欢迎使用SO!回答得好。。。稍微解释一下就好了。太好了!Ir somply隐藏窗口,然后再次显示。在窗口的“显示”过程中,它会自动聚焦!这是迄今为止最好的!!