如何编写VBA在新会话打开Internet Explorer?(How to code vba to

2019-07-17 21:42发布

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

  set ie=new InternetExplorer  

但它开启了旧会话中,即,我想对于每一个登录,请帮我开新的会话,我GOOGLE了很多关于它,但最终有任何解决方案。 这是我的代码

 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

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

Answer 1:

显然, -nomerge参数将防止会话合并。

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


Answer 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


Answer 3:

这个答案改变后,对我的作品:

Dim IE As InternetExplorer

Dim IE As Object


文章来源: How to code vba to open internet explorer in new session?