Saltar al contenido

Pausar macro mientras internet explorer trabaja


Recommended Posts

publicado

Buenas tardes a todos.

En esta macro:

Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Public Const MOUSEEVENTF_RIGHTDOWN As Long = &H8
Public Const MOUSEEVENTF_RIGHTUP As Long = &H10
Sub ABRIR_IE()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "http://www.paginaweb.html"
While IE.Busy
DoEvents
Wend
IE.Visible = True
DoEvents
Application.ScreenUpdating = False
Sheets("Hoja1").Visible = True
Sheets("Hoja2").Visible = True
Application.WindowState = xlMinimized 'minimizar excel
Application.Wait Time + TimeSerial(0, 0, 14)
SetCursorPos 900, 581 'Boton aceptar informacion
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.Wait Time + TimeSerial(0, 0, 3)
If Sheets("Controlados").Range("r2") = "MANUAL" Then
SetCursorPos 747, 500 'Boton entrada manual
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.Wait Time + TimeSerial(0, 0, 3)
SendKeys "XXXXXXX{tab}XXXXXX{tab}~", True
Application.Wait Time + TimeSerial(0, 0, 3)
SendKeys "XXXXXXXX{tab}~", True
Application.Wait Time + TimeSerial(0, 0, 1)
SendKeys "~", True
Application.Wait Time + TimeSerial(0, 0, 2)
SendKeys "~", True
Else
SetCursorPos 821, 406 'Boton entrada tarjeta
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.Wait Time + TimeSerial(0, 0, 12)
SendKeys "~"
Application.Wait Time + TimeSerial(0, 0, 10)
SendKeys "XXXXXXXX~", True
Application.Wait Time + TimeSerial(0, 0, 4)
SendKeys "~", True
Application.Wait Time + TimeSerial(0, 0, 2)
End If
Application.Wait Time + TimeSerial(0, 0, 12)
SetCursorPos 947, 66 'x Maximizar ventana
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.Wait Time + TimeSerial(0, 0, 10)
SetCursorPos 66, 112 'Boton
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.Wait Time + TimeSerial(0, 0, 10)
SetCursorPos 126, 184 'Boton hoy
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.Wait Time + TimeSerial(0, 0, 7)
If Sheets("Controlados").Range("I2") = "NO" Then
SetCursorPos 1236, 291
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Else
SetCursorPos 1236, 315 'Señalar
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
End If
Application.Wait Time + TimeSerial(0, 0, 1)
SetCursorPos 145, 717 'Boton modificar
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.Wait Time + TimeSerial(0, 0, 10)
SetCursorPos 583, 187 'Boton comentarios
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.Wait Time + TimeSerial(0, 0, 7)
Sheets("Controlados").Range("a31").Copy
SetCursorPos 387, 337 'Señalar comentarios
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.Wait Time + TimeSerial(0, 0, 1)
SendKeys "^v"
SetCursorPos 290, 642
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Application.Wait Time + TimeSerial(0, 0, 1)
Sheets("Controlados").Range("m2").Copy
SendKeys "^v"
Application.Wait Time + TimeSerial(0, 0, 1)
SendKeys "{tab}"
Sheets("Controlados").Range("a6").Copy
SendKeys "^v"
Application.Wait Time + TimeSerial(0, 0, 1)
SendKeys "{tab}"
Sheets("Controlados").Range("m6").Copy
SendKeys "^v"
Application.Wait Time + TimeSerial(0, 0, 1)
SetCursorPos 54, 722 'Boton guardar
mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0
mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0
Sheets("Hoja1").Visible = False
Sheets("Hoja2").Visible = False
Application.ScreenUpdating = True
End Sub[/CODE]

Me logueo en una pagina web. Es un servlet y utilizo este metodo, porque segun he mirado no hay metodo post para javascript.

Mi problema es que utilizo una intranet, y la velocidad de navegacion depende mucho de los ordenadores que haya conectados, por lo que el metodo de hacer pausas, (aunque doy bastante tiempo) a veces me falla y ya se descuadra toda la macro.

Estoy mirando

While IE.readyState <> READYSTATE_COMPLETE: DoEvents: Wend

Lo que intento es pausar la macro y que no continue hastaque cargue la pagina, o si pulso un boton, que acabe de salir otra ventana donde debo ingresar datos y no tener que hacerlo a ojo con

Application.Wait Time + TimeSerial(0, 0, 1), por ejemplo.

A ver si alguien me puede arrojar algo de luz.

Muchas gracias.

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

  • 109 ¿Te parecen útiles los tips de las funciones? (ver tema completo)

    1. 1. ¿Te parecen útiles los tips de las funciones?


      • No
      • Ni me he fijado en ellos

  • Ayúdanos a mejorar la comunidad

    • Donaciones recibidas este mes: 0.00 EUR
      Objetivo: 130.00 EUR
  • Archivos

  • Estadísticas de descargas

    • Archivos
      187
    • Comentarios
      97
    • Revisiones
      29

    Más información sobre "Un juego del Rabino en Excel"
    Última descarga
    Por pegones1

    2    1

  • Crear macros Excel

  • Mensajes

    • Que tal nuevamente,  adjunto una solución alternativa: =MAX(A:.A)-BYROW(F4:.AK20,LAMBDA(r,BUSCAR(2,1/(r=0),F3:.AK3))) Cabe mencionar que esta solución requiere funciones nuevas como RECORTAR.RANGO. CONTADOR FINAL (Solucion).xlsb
    • Buenos días,  espero se encuentren bien de salud compañeros, Favor me podrían ayuda con lo siguientes como se podría hacer cuando tengo una tabla dinámica que  amedida que se aumente las columnas fechas con data un formula que se coloco al final busque o analice siempre la ultima fila y columna de la fecha. Coloco un ejemplo
    • @JSDJSD Excelentes, GRACIAS POR TU SOPORTE , me ayudo demasiado es exactamente lo que quería. 5 ESTRELLAS
    • 'Opción 1 Sub FiltrarSKUPorFecha(): Application.ScreenUpdating = False Dim ultimaFila As Long, fila As Long Dim diccionarioSKU As Object Dim listaEliminar As Object Dim fechaActual As String, fechaSiguiente As String Dim f As Variant With Sheets("Consolidado") ultimaFila = .Cells(.Rows.Count, 1).End(xlUp).Row ' Crear diccionarios para comparar SKU y almacenar filas a eliminar Set diccionarioSKU = CreateObject("Scripting.Dictionary") Set listaEliminar = CreateObject("Scripting.Dictionary") ' Recorrer desde la primera fila hasta la penúltima For fila = 2 To ultimaFila - 1 fechaActual = .Cells(fila, 1).Value fechaSiguiente = .Cells(fila + 1, 1).Value ' Solo comparar la fecha actual con la siguiente (inmediatamente superior) If fechaActual <> fechaSiguiente Then diccionarioSKU.RemoveAll ' Limpiar el diccionario antes de llenarlo ' Guardar los SKU de la fecha siguiente (solo de la siguiente) For f = fila + 1 To ultimaFila If .Cells(f, 1).Value <> fechaSiguiente Then Exit For diccionarioSKU(.Cells(f, 2).Value) = 1 Next f ' Revisar los SKU de la fecha actual y marcar los que deben eliminarse For f = fila To 2 Step -1 If .Cells(f, 1).Value <> fechaActual Then Exit For ' Solo eliminar si el SKU no está en la fecha siguiente If Not diccionarioSKU.exists(.Cells(f, 2).Value) Then listaEliminar(f) = 1 ' Marcar fila para eliminar después End If Next f ' Ya no es necesario seguir buscando después de comparar la primera y la siguiente fecha Exit For End If Next fila ' Eliminar las filas marcadas sin afectar el bucle principal For Each f In listaEliminar.keys .Rows(f).Delete Next End With MsgBox "Completado correctamente.", vbInformation End Sub 'Opción 2 Sub FiltrarSKUPorFecha1(): Application.ScreenUpdating = False Dim ultimaFila As Long, fila As Long Dim listaEliminar As Collection Dim fechaActual As String, fechaSiguiente As String Dim f As Variant, i As Long Dim SKUExiste As Boolean With Sheets("Consolidado") ultimaFila = .Cells(.Rows.Count, 1).End(xlUp).Row ' Inicializar la colección para marcar las filas a eliminar Set listaEliminar = New Collection ' Recorrer desde la primera fila hasta la penúltima For fila = 2 To ultimaFila - 1 fechaActual = .Cells(fila, 1).Value fechaSiguiente = .Cells(fila + 1, 1).Value ' Solo comparar la fecha actual con la siguiente (inmediatamente superior) If fechaActual <> fechaSiguiente Then ' Revisar los SKU de la fecha actual y marcar los que deben eliminarse For f = fila To 2 Step -1 If .Cells(f, 1).Value <> fechaActual Then Exit For ' Comprobar si el SKU está en la fecha siguiente SKUExiste = False For i = fila + 1 To ultimaFila If .Cells(i, 1).Value <> fechaSiguiente Then Exit For If .Cells(i, 2).Value = .Cells(f, 2).Value Then SKUExiste = True Exit For End If Next i ' Si el SKU no se encuentra en la fecha siguiente, marcar para eliminar If Not SKUExiste Then listaEliminar.Add f ' Marcar fila para eliminar después End If Next f ' Ya no es necesario seguir buscando después de comparar la primera y la siguiente fecha Exit For End If Next fila ' Eliminar las filas marcadas sin afectar el bucle principal For Each f In listaEliminar .Rows(f).Delete Next f End With MsgBox "Completado correctamente.", vbInformation End Sub   TABLA ELIMINAR.xlsm
  • Visualizado recientemente

    • No hay usuarios registrado para ver esta página.
×
×
  • Crear nuevo...

Información importante

Echa un vistazo a nuestra política de cookies para ayudarte a tener una mejor experiencia de navegación. Puedes ajustar aquí la configuración. Pulsa el botón Aceptar, si estás de acuerdo.