Excel 在现有Internet Explorer窗口中导航到新URL
我正在尝试通过Excel 在现有Internet Explorer窗口中导航到新URL,excel,vba,internet-explorer,window,Excel,Vba,Internet Explorer,Window,我正在尝试通过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 Unt
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
IE没有导航到。作为类似的/经过调整的替代方案,这里是我最喜欢的功能 此函数返回一个对象,表示现有的
InternetExplorer
实例(如果有),否则返回一个新创建的实例
Function GetIE() As Object
'return an object for the open Internet Explorer window, or create new one
For Each GetIE In CreateObject("Shell.Application").Windows() 'Loop to find
If (Not GetIE Is Nothing) And GetIE.Name = "Internet Explorer" Then Exit For 'Found!
Next GetIE
If GetIE Is Nothing Then Set GetIE=CreateObject("InternetExplorer.Application")'Create
GetIE.Visible = True 'Make IE window visible
End Function
更多信息和示例。
IE.navigate”http://www.google.com“
谢谢Tim,这帮助解决了这一部分,但现在它突出显示了getIE=True,我熟悉PHP并从那里调用函数,但是我在VBA中做的调用正确吗?你不能给一个函数赋值-我不清楚你想用这行做什么。谢谢Tim,接近了,但我想要的是打开现有的IE窗口,转到新的URL yahoo.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
Function GetIE() As Object
'return an object for the open Internet Explorer window, or create new one
For Each GetIE In CreateObject("Shell.Application").Windows() 'Loop to find
If (Not GetIE Is Nothing) And GetIE.Name = "Internet Explorer" Then Exit For 'Found!
Next GetIE
If GetIE Is Nothing Then Set GetIE=CreateObject("InternetExplorer.Application")'Create
GetIE.Visible = True 'Make IE window visible
End Function