gpt4 book ai didi

internet-explorer - 如何编写vba代码以在新 session 中打开Internet Explorer?

转载 作者:行者123 更新时间:2023-12-02 13:04:58 24 4
gpt4 key购买 nike

几个月来我一直在努力完成这项工作,如何编写 VBA 代码以在新 session 中打开 Internet Explorer 我有一个具有多个登录名的应用程序,我需要使用自动化同时打开它们,我已经使用了

  set ie=new InternetExplorer  

但它会在旧 session 中打开 IE,我想为每次登录打开新 session ,请帮助我,我用谷歌搜索了很多,但最终没有任何解决方案。 这是我的代码

 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 中打开,该网页已打开,请帮助

最佳答案

显然 -nomerge 参数会阻止 session 合并。

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

更新

根据您的评论,您需要获取 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

关于internet-explorer - 如何编写vba代码以在新 session 中打开Internet Explorer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14184340/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com