我正在尝试通过 ie.Navigate
获取现有(打开的)IE 窗口加载新 URL。
下面是我的工作表代码,单击按钮即可加载网站:
Private Sub Sendit_Click()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.navigate "https://www.yahoo.com"
Do
Loop Until IE.ReadyState = READYSTATE_COMPLETE
GetIE
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
此代码位于我的模块中:
Function GetIE()
Dim shellWins As ShellWindows
Dim IE As InternetExplorer
Set shellWins = New ShellWindows
If shellWins.Count > 0 Then
' Get IE
Set IE = shellWins.Item(0)
Else
' Create IE
Set IE = New InternetExplorer
IE.Visible = True
End If
IE.navigate "http://www.google.com"
Set shellWins = Nothing
Set IE = Nothing
End Function
IE 无法导航至 http://www.google.com .
最佳答案
Sub TestGetIE()
Dim IE As Object
Set IE = CreateObject("Internetexplorer.Application")
IE.Visible = True
IE.navigate "https://www.yahoo.com"
WaitFor IE
Set IE = GetIE("https://www.yahoo.com")
IE.navigate "http://www.google.com"
End Sub
Sub WaitFor(IE)
Do
Loop Until IE.readyState = READYSTATE_COMPLETE
End Sub
Function GetIE(sLocation As String) As Object
Dim objShell As Object, objShellWindows As Object, o As Object
Dim sURL As String
Dim retVal As Object
Set retVal = Nothing
Set objShell = CreateObject("Shell.Application")
Set objShellWindows = objShell.Windows
For Each o In objShellWindows
sURL = ""
'check the URL and if it's the one you want then
' assign it to the return value
sURL = o.LocationURL
If sURL Like sLocation & "*" Then
Set retVal = o
Exit For
End If
Next o
Set GetIE = retVal
End Function
关于excel - 导航到现有 Internet Explorer 窗口中的新 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31167200/