Close JavaScript Alert Using VBA Automation

后端 未结 2 1439
眼角桃花
眼角桃花 2020-12-21 12:36

I am searching for a way to close a Javascript pop-up/message box (i.e. not a NEW IE window, but a scripted alert()) that loads when a webpage is loaded.

相关标签:
2条回答
  • 2020-12-21 13:26

    One work-around could be to recognize when your script is stuck and then just send the keystroke "enter" to close the pop-up.

    0 讨论(0)
  • 2020-12-21 13:33

    Have you had a look at using the MS XML classes for posting the data directly and parsing the result? This is much faster than IE automation although admittedly not always possible

    Edit: Not really, we're just using the classes to handle the request and response, we don't actually use XML, I put this together for someone a while back to give you an idea:

    Sub GetDataXML()
    
    Dim strPostText As String, strResponse As String
    Dim Pressure As Double, Temperature As Double
    Dim XMLrequest As Object
    
    Pressure = CDbl(InputBox("Enter the Pressure"))
    Temperature = CDbl(InputBox("Enter the Temperature"))
    
    strPostText = "lang=english&calc=standard&druck=" & Pressure & "&druckunit=1&temperatur=" & Temperature & "&tempunit=1&Submit=Calculate"
    
    Set XMLrequest = CreateObject("MSXML2.XMLHTTP")
    
    With XMLrequest
        .Open "POST", "http://www.peacesoftware.de/einigewerte/calc_co2.php5", False
        .setRequestHeader "Content-type", "application/x-www-form-urlencoded"
        .send (strPostText)
        Do: DoEvents: Loop Until .readyState = 4
        strResponse = .responseText
        .abort
    End With
    
    Debug.Print strResponse
    
    End Sub
    

    It is even easier if you are using a query table in excel as this handles any parsing of the data.

    Does the above help you?

    0 讨论(0)
提交回复
热议问题