¿Cómo puedo manipular una ventana emergente con VBA?

Tengo un código, que abre una página web, rellena el formulario y da clic a los botones necesarios todo funciona correctamente, el problema es que al dar el último clic el resultado se muestra en una segunda ventana, y necesita trabajar con esta segunda ventana para importar los datos a Excel y también guardar el archivo como PDF.

Pregunta general, como intercepto y manipular la ventana emergente. Encontré artículos parecidos sin éxito, agradezco su ayuda.

Sub Extraerdatos()
Dim IE As Object
Dim MiCombo As Object
Dim c As Long, UltimaFila As Long
Dim Celda As Range
Const OLECMDID_PRINT = 6
Const OLECMDEXECOPT_DONTPROMPTUSER = 2
Const PRINT_WAITFORCOMPLETION = 2
Set IE = CreateObject("InternetExplorer.Application")
Let UltimaFila = Cells(Rows.Count, 1).End(xlUp).Row
IE.Visible = True
IE.Navigate2 "http://srv.redinservsa.com/busquedaClienteGeneral.php"
Do While IE.readyState <> READYSTATE_COMPLETE
    DoEvents
Loop
For Each Celda In Range("A2:A" & UltimaFila)
With IE
Set MiCombo = IE.Document.all("ltTipo")
        MiCombo.selectedIndex = 2
        .Document.all("ltTipo") = "Cédula"
        Application.Wait (Now + TimeValue("0:00:01"))
        .Document.all("ltNombres").Value = Celda.Value
         Application. Wait (Now + TimeValue("0:00:01"))
        . Document. All("enviar"). Click
        Application. Wait (Now + TimeValue("00:00:01"))
        . Document. GetElementsByClassName("cont")(0). Click
          Application. Wait (Now + TimeValue("00:00:02"))
' despues de esto se muestra mi ventana emergente intente hacerlo con sendkeys pero tampo funciona.
End With
Application. Wait (Now + TimeValue("00:00:03"))
SendKeys "^p"
Application. Wait (Now + TimeValue("00:00:03"))
SendKeys "{ENTER}"
Application.Wait (Now + TimeValue("00:00:01"))
SendKeys Celda.Value
Application.Wait (Now + TimeValue("00:00:01"))
SendKeys "~"
Application.Wait (Now + TimeValue("00:00:08"))
Next Celda
IE.Quit
MsgBox "Proceso finalizado"
End Sub

1 respuesta

Respuesta
2

Estimado si a alguien le interesa les dejo la solución que encontré para este problema

marker = 0
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
    On Error Resume Next
    my_url = objShell.Windows(x).document.Location
    my_title = objShell.Windows(x).document.Title
    If my_url Like "http://192.168.1.76/frmPrincipal.aspx" & "*" Then
        Set ie = objShell.Windows(x)
        marker = 1
        Exit For
    Else
    End If
Next
If marker = 0 Then
 MsgBox ("A matching webpage was NOT found")
Else
' aqui el codigo a usarse en la nueva ventana
End If

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas