0

I have an Excel VBA macro that

  1. opens IE,
  2. navigates to the Medicare website,
  3. logs me in,
  4. compares the claims listed on the website with those already in the workbook
  5. alerts me to any differences

It is during the log-in step that I have a problem, so I've reproduced that portion of my code below. As soon as the .click line is executed a pop-up window appears asking the user to click the OK button in order to proceed. Macro execution is suspended until I manually click the OK button on the pop-up.

The source code behind the http://www.mymedicare.gov web page has information relative to the pop-up, but I haven't been able to figure out how to use it so that I can programmatically click the pop-up OK button.

Several years ago, I posted this question and Tim Williams provided an excellent solution based on interacting with the javascript behind the pop-up window. Medicare has since changed the code behind the web page and Tim's solution no longer handles the pop-up window. I've tried a lot of variations on Tim's theme but haven't found the solution.

Any help in terms of figuring out how to programmatically click the pop-up's OK button would be much appreciated.

note: For the purpose of this question, any user id and password can be used (I've out abcde and 12345 in the code below). 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" 
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
ron
  • 1,456
  • 3
  • 18
  • 27

1 Answers1

1

This worked for me

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
    Dim doc As Object

    Set doc = ie.Document

    doc.getElementById("ctl00_ContentPlaceHolder1_ctl00_HomePage_SWEUserName").Value = "abcde"
    doc.getElementById("ctl00_ContentPlaceHolder1_ctl00_HomePage_SWEPassword").Value = "12345"
    doc.getElementById("ctl00_ContentPlaceHolder1_ctl00_HomePage_Agree").Value = "True"

    doc.parentWindow.execScript "window.ConfirmationPopup = function(){null;}", "jscript"

    doc.getElementById("ctl00_ContentPlaceHolder1_ctl00_HomePage_SignIn").Click

End Sub
Tim Williams
  • 154,628
  • 8
  • 97
  • 125