Note: The other languages of the website are Google-translated. Back to English
Iniciar sesión  \/ 
x
or
x
Regístrate  \/ 
x

or

¿Cómo repetir o repetir una macro cada X minutos en Excel?

Mientras trabaja con Microsoft Excel, es posible que deba crear macros para realizar algunas operaciones. Por ejemplo, desea crear una macro para copiar automáticamente un rango de datos a un nuevo lugar. Como los datos se cambiarán con frecuencia, necesita que esta macro se ejecute automáticamente cada 5 minutos sin activarla manualmente para sincronizar estos dos rangos de datos. ¿Cómo lograrlo? El método de este artículo puede ayudarte.

Repita o repita una macro cada X minutos en Excel


Repita o repita una macro cada X minutos en Excel

El siguiente código VBA puede ayudarlo a repetir una macro cada X minutos en Excel. Haz lo siguiente.

1. Prensa otro + F11 llaves al mismo tiempo para abrir el Microsoft Visual Basic para aplicaciones ventana.

2. En el Microsoft Visual Basic para aplicaciones ventana, haga clic en recuadro > Módulo. Luego copie y pegue el siguiente código VBA en el Código ventana. Ver captura de pantalla:

Código de VBA: repita o repita una macro cada X minutos en Excel

Sub ReRunMacro()
Dim xMin As String

'Insert your code here
    xMin = GetSetting(AppName:="Kutools", Section:="Macro", Key:="min", Default:="")
    If xMin = "Exit" Then
    SaveSetting "Kutools", "Macro", "min", "False"
    Exit Sub
    End If
    If (xMin = "") Or (xMin = "False") Then
      xMin = Application.InputBox(prompt:="Please input the interval time you need to repeat the Macro", Title:="Kutools for Excel", Type:=2)
      SaveSetting "Kutools", "Macro", "min", xMin
    End If
    If (xMin <> "") And (xMin <> "False") Then
      Application.OnTime Now() + TimeValue("0:" + xMin + ":0"), "ReRunMacro"
    Else
      Exit Sub
    End If
End Sub

<b>Nota</b>: En el código, reemplace esta línea 'Inserta tu código aquí con el código se ejecutará cada X minutos.

3. presione el F5 clave para ejecutar el código. En el apareciendo Kutools for Excel cuadro de diálogo, ingrese el intervalo de tiempo en el que repetirá la macro y luego haga clic en el OK botón. Ver captura de pantalla:

A partir de ahora, cierta macro se ejecutará repetidamente cada 5 minutos en su libro de trabajo.

<b>Nota</b>: Si necesita detener la ejecución de la macro y cambiar el intervalo del ciclo, copie el siguiente código VBA en el mismo Módulo ventana y presione el F5 clave para ejecutar el código. Luego, la macro se detendrá, vuelva a ejecutar el código anterior para especificar un nuevo intervalo.

Código de VBA: detiene la ejecución de la macro

Sub ExitReRunMacro()
SaveSetting "Kutools", "Macro", "min", "Exit"
End Sub

Office Tab - Navegación, edición y administración con pestañas de libros de trabajo en Excel:

Office Tab trae la interfaz con pestañas como se ve en navegadores web como Google Chrome, nuevas versiones de Internet Explorer y Firefox a Microsoft Excel. Será una herramienta que te ahorrará tiempo e insustituible en tu trabajo. Vea la demostración a continuación:

¡Haga clic para obtener una prueba gratuita de Office Tab!

Pestaña Office para Excel


Artículos relacionados:


Las mejores herramientas de productividad de oficina

Kutools para Excel resuelve la mayoría de sus problemas y aumenta su productividad en un 80%

  • Reutilizar: Inserte rápidamente fórmulas complejas, gráficos y cualquier cosa que hayas usado antes; Cifrar celdas con contraseña; Crear lista de distribución y enviar correos electrónicos ...
  • Barra de súper fórmula (edite fácilmente varias líneas de texto y fórmulas); Diseño de lectura (leer y editar fácilmente un gran número de celdas); Pegar en rango filtrado...
  • Combinar celdas / filas / columnas sin perder datos; Contenido de celdas divididas; Combinar filas / columnas duplicadas... Prevenir celdas duplicadas; Comparar rangos...
  • Seleccione Duplicado o Único Filas; Seleccionar filas en blanco (todas las celdas están vacías); Super Find y Fuzzy Find en muchos libros de trabajo; Selección aleatoria ...
  • Copia exacta Varias celdas sin cambiar la referencia de la fórmula; Crear referencias automáticamente a varias hojas; Insertar viñetas, Casillas de verificación y más ...
  • Extraer texto, Agregar texto, Eliminar por posición, Quitar espacio; Crear e imprimir subtotales de paginación; Convertir entre contenido de celdas y comentarios...
  • Súper filtro (guardar y aplicar esquemas de filtros a otras hojas); Orden avanzado por mes / semana / día, frecuencia y más; Filtro especial en negrita, cursiva ...
  • Combinar libros y hojas de trabajo; Combinar tablas basadas en columnas clave; Dividir datos en varias hojas; Conversión por lotes de xls, xlsx y PDF...
  • Más de 300 potentes funciones. Compatible con Office / Excel 2007-2019 y 365. Compatible con todos los idiomas. Fácil implementación en su empresa u organización. Características completas Prueba gratuita de 30 días. Garantía de devolución de dinero de 60 días.
pestaña kte 201905

Office Tab lleva la interfaz con pestañas a Office y hace que su trabajo sea mucho más fácil

  • Habilite la edición y lectura con pestañas en Word, Excel, PowerPoint, Publisher, Access, Visio y Project.
  • Abra y cree varios documentos en nuevas pestañas de la misma ventana, en lugar de en nuevas ventanas.
  • ¡Aumenta su productividad en un 50% y reduce cientos de clics del mouse todos los días!
officetab parte inferior
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    creativeperson97 · 1 months ago
    I am pasting the code below in which I have replaced the line to enter the code with my code. The error I am getting is- Compile error: Expected End Sub. Kindly help.

    Sub ReRunMacro()
    Dim xMin As String
    Sub Refresh()
    '
    ' Refresh Macro
    '

    '
    Sheets("Sheet1").Select
    ActiveWorkbook.RefreshAll
    Sheets("Pivot-Dash").Select
    End Sub


    xMin = GetSetting(AppName:="Kutools", Section:="Macro", Key:="min", Default:="")
    If xMin = "Exit" Then
    SaveSetting "Kutools", "Macro", "min", "False"
    Exit Sub
    End If
    If (xMin = "") Or (xMin = "False") Then
    xMin = Application.InputBox(prompt:="Please input the interval time you need to repeat the Macro", Title:="Kutools for Excel", Type:=2)
    SaveSetting "Kutools", "Macro", "min", xMin
    End If
    If (xMin <> "") And (xMin <> "False") Then
    Application.OnTime Now() + TimeValue("0:" + xMin + ":0"), "ReRunMacro"
    Else
    Exit Sub
    End If
    • To post as a guest, your comment is unpublished.
      crystal · 24 days ago
      Good day,
      You need to remove the Sub line and the End Sub line from your code.
      Sub Refresh() ' ' Refresh Macro ' ' Sheets("Sheet1").Select ActiveWorkbook.RefreshAll Sheets("Pivot-Dash").Select End Sub
      Change to:
      ' ' Refresh Macro ' ' Sheets("Sheet1").Select ActiveWorkbook.RefreshAll Sheets("Pivot-Dash").Select

  • To post as a guest, your comment is unpublished.
    LIMCA · 6 months ago
    Hi Jack,
    By mistake I entered 0.5 mins and it shows an error,
    I mean xMin is taken as 0.5 minutes.
    How to get rid and change it to 1 min?

    • To post as a guest, your comment is unpublished.
      crystal · 6 months ago
      Hi LIMCA,
      Sorry for the inconvenience. The code does not support entering decimals.

      Please stop the the looping by running the below VBA code, and then rerun the looping code and enter 1 into the popping up dialog box.

      Sub ExitReRunMacro()
      SaveSetting "Kutools", "Macro", "min", "Exit"
      End Sub
  • To post as a guest, your comment is unpublished.
    MOhammed · 7 months ago
    How to create a macro in excel with continuous loop and pressed key would be only pg up and pg down
  • To post as a guest, your comment is unpublished.
    davart · 8 months ago
    Hi very useful, however I think I messed up and set the time as 0.5 and now I cannot chage it, any ideas how to change the xMin Setting?
  • To post as a guest, your comment is unpublished.
    David · 8 months ago
    Hi, I messed up and set the time as 0.5 and now I cannot chage it, any ideas how to change the xMin Setting?
    • To post as a guest, your comment is unpublished.
      crystal · 8 months ago
      Hi David.
      As we mentioned at the end of the post, if you need to stop the execution of the macro and change the interval of the cycle, please copy the below VBA code into the same Module window and press the F5 key to run the code. Then the Macro will be stopped, please rerun the above code to specify a new interval.

      Sub ExitReRunMacro()
      SaveSetting "Kutools", "Macro", "min", "Exit"
      End Sub
      • To post as a guest, your comment is unpublished.
        David · 7 months ago
        Hey, Thanks! but im afraid the marco doenst even run, when I press F5 excel sends me this error msgs: Run time error 13 'Type Missmatch".

        I deleted it, but If I try to create it again the same error msg appears, my only guess is that I set the time as 0.5 and in the code, so no idea how to modify it now.

        Thanks Again for your help.
  • To post as a guest, your comment is unpublished.
    Padma · 8 months ago
    Hello, Just help me out on "insert your code here". I am a novice and need help on what to fill and how ! Thanks
    I am not getting it right

    • To post as a guest, your comment is unpublished.
      crystal · 8 months ago
      Hi Padma,
      The "insert your code here" indicate the VBA code you use to achieve some operation in Excel. Supposing you need to apply VBA to move a row to another sheet based on a specific value, and want to run the code every X minutes automatically, you need to place the VBA code here.
  • To post as a guest, your comment is unpublished.
    Mohit · 10 months ago
    Hey

    I have a query, your codes works perfectly fine and copies the data in my next columns every 5 minutes but after 3 hours all my columns get full as it is 2003 excel. Could you please help me with a code to check if no other column is vacant then create a new sheet and copy paste data into that sheet
  • To post as a guest, your comment is unpublished.
    ram2093@gmail.com · 1 years ago
    Please provide a Code for :


    "How to repeat or loop a Macro every X Seconds in Excel"


    Thank you
    • To post as a guest, your comment is unpublished.
      crystal · 1 years ago
      Hi,
      Please change the line "Application.OnTime Now() + TimeValue("0:" + xMin + ":0"), "ReRunMacro"" to
      Application.OnTime Now() + TimeValue("0:" + "0:" + xMin), "ReRunMacro"
  • To post as a guest, your comment is unpublished.
    ebolshakovv@gmail.com · 2 years ago
    Tell me more how to stop the execution of the macro and change the interval of the cycle?
    • To post as a guest, your comment is unpublished.
      crystal · 2 years ago
      Good daty,
      A new VBA code which can stop the macro has been added at the end of the article. Please have a try. Thank you for your comment.
  • To post as a guest, your comment is unpublished.
    jack1 · 2 years ago
    Tell me more how to stop the execution of the macro and change the interval of the cycle?
  • To post as a guest, your comment is unpublished.
    Ryan · 2 years ago
    Hi!
    This is great, but is there a way to get it to loop back up to the first row of the spreadsheet before beginning again?


    Thanks!
  • To post as a guest, your comment is unpublished.
    JIm · 3 years ago
    Thanks for this, works a treat. I'm a novice to coding so please forgive me if this is simple...

    How do I get the dialog box to appear again? I have it stuck on a 1 minute loop. Thanks.
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Good Day,
      Just break the code and run it again.
  • To post as a guest, your comment is unpublished.
    primeacademyresource@gmail.com · 3 years ago
    Great one! Please how do i stop the loop after say 10 times?
    • To post as a guest, your comment is unpublished.
      crystal · 3 years ago
      Good Day,
      You can get into the Code window to break the code (click on the Break button) manually to stop the loop.
      • To post as a guest, your comment is unpublished.
        Jack · 2 years ago
        Good day! I did not understand how to break the macro code to set the loop execution time again.Could you describe in more detail how to do this? Where is the value of the run cycle time recorded?
        • To post as a guest, your comment is unpublished.
          crystal · 2 years ago
          Hi Jack,
          My mistake.
          A new VBA code which can stop the macro has been added at the end of the article. Please have a try. Thank you for your comment.