Home > Software design >  How to close a web message from IE VBA?
How to close a web message from IE VBA?

Time:01-25

I,ve been dealing with a issue during my web scraping. My problem is that when I click to "Submit" a form, it pops-up a web message that I've not been able to close.

I´ve already try the sendKeys Method but no success. here is the link of the web page: https://www3.bcb.gov.br/CALCIDADAO/publico/corrigirPorIndice.do?method=corrigirPorIndice Here is a print of the info to put in the webpage Here is a print of the info to put in the webpage The message appers when you click the button on the left "Corrigir Valor" enter image description here the messege

enter image description here

obs. pressing enter or esc with the keyboard close it, but I`m not been able to do it in the code

here is the code if may be helpful

Sub atualizacao_valores()
Dim data_base As String
Dim data_atualizacao As String
Dim valor_face As String
Dim drp As HTMLFormElement
Dim html As HTMLDocument



Set ie = CreateObject("internetexplorer.application")
ie.navigate "https://www3.bcb.gov.br/CALCIDADAO/publico/exibirFormCorrecaoValores.do?method=exibirFormCorrecaoValores&aba=1"
ie.Visible = True
Do While ie.busy And ie.readyState <> "READYSTATE_COMPLETE"
DoEvents
Loop

data_base_ipcae = "01/2022"
data_atualizacao_ipcae = "12/2022"
valor_face = "100000"

Application.Wait (Now   TimeValue("00:00:02"))
Set html = ie.document
Set drp = html.getElementById("selIndice")

drp.selectedIndex = 4

ie.document.getelementsbytagname("input")(1).Value = data_base_ipcae
ie.document.getelementsbytagname("input")(2).Value = data_atualizacao_ipcae
ie.document.getelementsbytagname("input")(3).Value = valor_face


ie.document.getelementsbyclassname("botao")(0).Click
`here happens the pop up that I cant close


...
end sub

CodePudding user response:

I agree with the suggestion given by Tim Williams.

Adding code below just above the line when you click the button could suppress the Alert().

With html.parentWindow
   .execScript "window.alert = function(){return true;};", "JScript"
End With

Your modified code:

Sub atualizacao_valores()
    Dim data_base As String
    Dim data_atualizacao As String
    Dim valor_face As String
    Dim drp As HTMLFormElement
    Dim html As HTMLDocument
    
    Set ie = CreateObject("internetexplorer.application")
    ie.navigate "https://www3.bcb.gov.br/CALCIDADAO/publico/exibirFormCorrecaoValores.do?method=exibirFormCorrecaoValores&aba=1"
    ie.Visible = True
    Do While ie.busy And ie.readyState <> "READYSTATE_COMPLETE"
        DoEvents
    Loop
    
    data_base_ipcae = "01/2022"
    data_atualizacao_ipcae = "12/2022"
    valor_face = "100000"
    
    Application.Wait (Now   TimeValue("00:00:02"))
    Set html = ie.document
    Set drp = html.getElementById("selIndice")
    
    drp.selectedIndex = 4
    
    ie.document.getelementsbytagname("input")(1).Value = data_base_ipcae
    ie.document.getelementsbytagname("input")(2).Value = data_atualizacao_ipcae
    ie.document.getelementsbytagname("input")(3).Value = valor_face
    
    With html.parentWindow
        .execScript "window.alert = function(){return true;};", "JScript"
        
    End With
    
    ie.document.getelementsbyclassname("botao")(0).Click
    
    
End Sub

I have tested this code on my end and it is suppressing the Alert message.

You could test it and let us know your test results.

  • Related