I have a VBA macro that handles Internet Explorer, at some point when clicking an item, a new tab is opened in Internet Explorer.
My question is: How to change the focus of VBA to handle this new tab that was opened?
follow code:
Sub x()
Dim ie As InternetExplorer
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "http://www.comprasgovernamentais.gov.br/acesso-aos-sistemas/comprasnet-siasg"
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
Set objCollection = ie.Document.getElementsByTagName("a")
i = 0
n = objCollection.Length
Do While i < n
If objCollection(i).href = "https://www.comprasnet.gov.br/seguro/loginPortal.asp" Then
objCollection(i).Click
i = n
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
Sleep (3000)
End If
i = i + 1
Loop
ie.Document.getElementById("perfil").Item(2).Selected = True
ie.Document.getElementById("perfil").fireEvent "onchange"
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
Sleep (3000)
ie.Document.getElementById("txtLogin").Value = "xxxxxxx"
ie.Document.getElementById("txtSenha").Value = "xxxxxxx"
ie.Document.getElementById("acessar").Click
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
Sleep (3000)
Set objCollection = ie.Document.frames(1).Document.getElementsByTagName("div")
i = 0
n = objCollection.Length
Do While i < n
If objCollection(i).innertext = "IRP" Then
objCollection(i).fireEvent "onclick" 'após disparar este evento a nova aba é aberta
i = n
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
Sleep (3000)
End If
i = i + 1
Loop
End Sub