vba即导航多个会话

我使用VBA通过这个网站访问IE,但有一个问题,我不明白。 该网页跟踪是否有多个打开的窗口会话,并在我开始导航到另一个窗口时将其注销。 有没有办法继续会议,并导航回到前一页而不断开?

作为一个侧面说明,该网页不是一个公共领域。

这是我有什么不工作:

Dim IE As Object Set IE = New InternetExplorerMedium IE.Visible = True 'code to Login to webpage went here Set doc = IE.document doc.getElementById("txtFileNumber").Value = "12345678" doc.getElementById("cmdSearch").Click Do While .Busy Or .READYSTATE <> 4 DoEvents Loop Dim requested as Object Dim trans As String Set requested = doc.getElementById("TransitLink") If requested.isDisabled = False Then trans = requested.href End If IE.navigate trans ' <----msgbox comes up "Multiple sessions not allowed" 

这是HTML代码的一部分,如果这有帮助的话。

 <a id="TransitLink" title="In Transit" class="button" onClick="inqPopups[7] = window.open(this.href, 'popup7', 'WIDTH=350,HEIGHT=250,scrollbars,resizable,status,toolbar=yes'); (document.getElementById('txtFileNumber')).focus(); (document.getElementById('txtFileNumber')).select(); inqPopups[7].focus(); return false;" href="TransactionInTransit.aspx?... style="color:Blue;">In Transit</a> var inqPopups = new Array(); function closeSubWindow() { for (var i = 0; i < inqPopups.length; i++) { if (inqPopups[i] && !inqPopups[i].closed) { inqPopups[i].close(); } } } 

尝试使用With IE并做所有的代码和End With

 Dim IE As Object Set IE = New InternetExplorerMedium Wtih IE .Visible = True 'code to Login to webpage went here Set doc = IE.document doc.getElementById("txtFileNumber").Value = "12345678" doc.getElementById("cmdSearch").Click Do While .Busy Or .readyState <> 4 DoEvents Loop Dim requested As Object Dim trans As String Set requested = doc.getElementById("TransitLink") If requested.isDisabled = False Then trans = requested.href End If .navigate trans ' Rest of code .Quit ' close ie window End With 'once done with IE window 

既然你已经Set IE = New它每次都会创build一个新的IE实例。 所以为了将它全部保存在一个窗口中,您必须使用With IE End With方法。