2012-06-25 28 views

回答

2

我需要我的电子表格来执行功能后,“焦点设置”到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 
1

设置.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对象:MSDN

0

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

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 
相关问题