我有一个 Excel VBA 宏
- 打开 IE,
- 导航至 Medicare 网站,
- 让我登录,
- 将网站上列出的声明与工作簿中已有的声明进行比较
- 提醒我任何差异
在登录步骤中我遇到了问题,因此我复制了下面的那部分代码。一旦执行 .click
行,就会出现一个弹出窗口,要求用户单击 OK 按钮才能继续。宏执行会暂停,直到我手动单击弹出窗口中的确定按钮。
http://www.mymedicare.gov背后的源代码网页包含与弹出窗口相关的信息,但我无法弄清楚如何使用它,以便我可以通过编程方式单击弹出窗口 确定 按钮。
如果您能提供有关如何以编程方式单击弹出窗口的确定按钮的任何帮助,我们将不胜感激。
note: For the purpose of this question, any user id and password can be used. If you handle the pop-up you'll be passed to a page that says something like incorrect user id / password.
That will indicate that you've been successful in handling the pop-up.
Sub Medicare_Claims()'
' Update the status bar
Application.StatusBar = "Running the Medicare Claims subroutine"
' Open the "MyMedicare web page
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.Navigate "https://www.mymedicare.gov/"
End With
' Loop until the page is fully loaded
Do Until ie.ReadyState = 4 And Not ie.Busy
DoEvents
Loop
' Log-in
ie.Document.all.Item("ctl00_ContentPlaceHolder1_ctl00_HomePage_SWEUserName").Value = "abcde"
ie.Document.all.Item("ctl00_ContentPlaceHolder1_ctl00_HomePage_SWEPassword").Value = "12345"
ie.Document.getElementById("ctl00_ContentPlaceHolder1_ctl00_HomePage_SignIn").Click
' Loop until the page is fully loaded
Do Until ie.ReadyState = 4 And Not ie.Busy
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:15"))
' Navigate further to the Search Claims" web page
ie.Navigate "https://www.mymedicare.gov/searchclaims.aspx"
最佳答案
尝试Application.SendKeys "{ENTER}", True
在您的登录代码之后。
另外,尝试添加
Do: DoEvents: Loop Until Not objIE.Busy
和
Do While objIE.readyState <> 4: DoEvents: Loop
任何时候您需要加载页面。根据我的经验,将两者结合在一起效果很好,而仅使用其中之一有时会产生错误,而使用 Application.Wait
会不必要地减慢您的代码速度。
关于javascript - 使用 IE 导航时处理弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17773523/