在现有IE上优秀VBA新的URL

我是相当新的VBA,并试图获得一个现有的打开的IE窗口通过(IE.navigate)加载一个新的URL,但似乎并没有工作。

我的代码在工作表中运行一个button,点击后将加载到网站,简单的东西

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 

但现有的窗口不会更改并导航到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