2013-01-06 37 views
2

我很努力,因为几个月来完成这件事,如何编写VBA来打开新的会话的Internet Explorer我有许多登录我需要同时打开它们使用自动化的应用程序,我已经使用如何在新会话中编码vba以打开Internet Explorer?

set ie=new InternetExplorer 

但它会在旧会话中打开ie,我想为每个登录都打开新会话,请帮助我,我为它搜索了很多内容,但最终没有找到任何解决方案。 这是我的代码

Function GetIE() As InternetExplorer 

    Dim WScript 
Dim objShellWindows 

Set objShell = CreateObject("Shell.Application") 
Set objShellWindows = objShell.Windows 
Set WScript = CreateObject("WScript.Shell") 


Dim ieStarted 
ieStarted = False 

    Dim ieError 
    ieError = False 

    Dim seconds 
     seconds = 0 

    While (Not ieStarted) And (Not ieError) And (seconds < 30) 

If (Not objShellWindows Is Nothing) Then 
    Dim objIE As InternetExplorer 
    Dim IE 


    For Each objIE In objShellWindows 

     If (Not objIE Is Nothing) Then 

      If IsObject(objIE.Document) Then 
       Set IE = objIE.Document 

       If VarType(IE) = 8 Then 

        If IE.Title = EmptyTitle Then 
         If Err.Number = 0 Then 
          IE.Write LoadingMessage 

          objIE.navigate Sheet1.Login.Text 
         ieStarted = True 
         Set GetIE = objIE 


         Else 

         MsgBox ErrorMessage 
          Err.Clear 
          ieError = True 

          Exit For 
         End If 
        End If 
       End If 
      End If 
     End If 

     Set IE = Nothing 
     Set objIE = Nothing 
    Next 
End If 

Application.Wait Now + TimeValue("00:00:1") 
seconds = seconds + 1 
Wend 

Set objShellWindows = Nothing 
Set objShell = Nothing 



    End Function 

这段代码即时通讯能够打开浏览器,但可悲的是我的网页是在已经开通请帮助

回答

4

显然,-nomerge参数将防止会话合并Outlook中打开。

Shell("iexplore.exe -nomerge http://www.yoursite.com") 

UPDATE

根据你的评论,你需要获得IE对象。您可以使用以下方法:

Dim wshShell 
Set wshShell = WScript.CreateObject("WScript.Shell") 

wshShell.Run "iexplore -nomerge http://www.google.com" 

Dim objShell 
Set objShell = CreateObject("Shell.Application") 

Dim objShellWindows 
Set objShellWindows = objShell.Windows 

Dim i 
Dim ieObject 
For i = 0 To objShellWindows.Count - 1 
    If InStr(objShellWindows.Item(i).FullName, "iexplore.exe") <> 0 Then 
     Set ieObject = objShellWindows.Item(i) 
     If VarType(ieObject.Document) = 8 Then 
      MsgBox "Loaded " & ieObject.Document.Title 
      Exit For 
     End If 
    End If 
Next 

Set ieObject = Nothing 
Set objShellWindows = Nothing 
Set objShell = Nothing 
Set wshShell = Nothing 
+0

这是在一个新的会话打开浏览器,但我无法得到即对象,请检查我附上的代码。我需要的功能是“当我们从文件菜单打开新的会话”时 – nothingisimpossible

+0

您可能可以适应[此答案](http://stackoverflow.com/a/7595348/74757)。我会看看我是否可以简化它,如果可以的话,会更新我的帖子。 –

+0

非常感谢你所提供的链接中的代码是完美的工作,除非我需要让我的主页空白才能正常工作:( – nothingisimpossible

2

使用Excel 2010 - 这是我使用的命令按钮。将google.com替换为您想在其他浏览器中打开的网站。

Private Sub commandname_Click() 

'Opens an Explorer with a web site 

Dim IE As InternetExplorer 

    Set IE = CreateObject("InternetExplorer.Application") 

    IE.navigate ("http://WWW.GOOGLE.COM") 

    IE.Visible = True 

End Sub 
0

This answer作品对我来说变化后:

Dim IE As InternetExplorer 

Dim IE As Object 
相关问题