Llo*_*nks 4 internet-explorer vba setfocus
有人知道如何使用 Visual Basic 将焦点设置到 IE 对象上吗?我已经试过了myieobject.SetFocus,但是这个语句的编译器错误。
小智 5
我需要一个我的电子表格在执行一个功能后“设置焦点”到 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
Run Code Online (Sandbox Code Playgroud)