0
I have a macro in VBA that handles Internet Explorer, at certain point when clicking an item, a new tab opens in Internet Explorer.
My doubt is: how to change the focus of VBA to manipulate this new tab that has been opened?
follows 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