VBA,在关闭并重新打开浏览器后获取并管理活动网页 [英] VBA, get and manage the active web page after browser closing and re-opening
问题描述
在我的访问权限和VBA应用程序我必须获取和管理Web Order应用程序的网页.通常,我使用本文中指出的解决方案,该解决方案通常可以正常运行:
in my Access & VBA application i Have to get and manage a web page of a web order application. Normally, I use the solution indicated in this post, which normally works perfectly:
但是,现在我有另一个旧的Web应用程序可以与Access软件连接.在此Web应用程序中,登录后,网页会自行关闭并与第一个用户页面打开另一个浏览器会话.换句话说:
But, now I have another old web application to connect with my Access software. In this web application, after login, the web page closes itself and open an other browser session with the first user page. In other words:
1)用户使用用户凭据填写登录表单 2)登录后,登录网页关闭浏览器 3)使用Web应用程序控制面板打开另一个浏览器会话
1) The user fill the login form with the user credentials 2) After login, the login web page closes the browser 3) An other browser session opens with the web app control panel
如果使用链接的解决方案,则会看到错误.如何在新的浏览器会话中获取新网页,该网页在登录后会自动打开?
If I use the linked solution, I see an error. How can I get the new web page, in the new browser session, which opens it self after login?
谢谢!
编辑
我尝试了以下代码(我的目的是在网页中设置文本值).但是,很奇怪,仅当我在代码中放入一个文本框时,它才起作用:也许代码必须等待某个事件!我该怎么解决?
I have tried the following code (my purpose is set a text value in the web page). But, very strange, it works only if I put a text box in my code: maybe the code must wait some event! How can I solve it?
Dim SWs As SHDocVw.ShellWindows, vIE As SHDocVw.InternetExplorer
Dim winShell As Shell
Dim dt As Date
dt = DateAdd("s", 10, DateTime.Now)
Dim ieA As InternetExplorer
Dim IeDocA As HTMLDocument
Do While dt > DateTime.Now
Set winShell = New Shell
For Each ieA In winShell.Windows
If ieA.LocationURL = sURL Then
ieA.Visible = True
ieA.Silent = True
Do While ieA.Busy: DoEvents: Loop
Do Until ieA.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
Set IeDocA = ieA.Document
//only with this msgbox it works, how can I do this w/out it?
MsgBox IeDocA.title
With IeDocA
.getElementsByName("text").value="something"
End With
Set winShell = Nothing
Exit Do
End If
Next ieA
Set winShell = Nothing
DoEvents
Loop
推荐答案
您可以在窗口中查找URL.您将需要对Microsoft Shell控件和自动化的引用.
You can Look for the URL in the window. You will need a reference to Microsoft Shell Controls and Automation.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Desc: The Function gets the Internet Explorer window that has the current
' URL from the sURL Parameter. The Function Timesout after 30 seconds
'Input parameters:
'String sURL - The URL to look for
'Output parameters:
'InternetExplorer ie - the Internet Explorer window holding the webpage
'Result: returns the the Internet Explorer window holding the webpage
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function GetWebPage(sUrl As String) As InternetExplorer
Dim winShell As Shell
Dim dt As Date
dt = DateAdd("s", 30, DateTime.Now)
Dim ie As InternetExplorer
Do While dt > DateTime.Now
Set winShell = New Shell
'loop through the windows and check the internet explorer windows
For Each ie In winShell.Windows
'check the URL
If ie.LocationURL = sUrl Then
'set some properties
ie.Visible = True
ie.Silent = True
Set GetWebPage = ie
'loop while IE is busy
Do While ie.Busy
DoEvents
Loop
Set winShell = Nothing
Exit Do
End If
Next ie
Set winShell = Nothing
DoEvents
Loop
End Function
这篇关于VBA,在关闭并重新打开浏览器后获取并管理活动网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!