Note: The other languages of the website are Google-translated. Back to English
Logáil isteach  \/ 
x
or
x
Cláraigh  \/ 
x

or

Conas Macra a athdhéanamh nó a lúbadh gach X nóiméad in Excel?

Agus tú ag obair le Microsoft Excel, b’fhéidir go mbeidh ort Macraí a chruthú chun roinnt oibríochtaí a bhaint amach. Mar shampla, ba mhaith leat Macra a chruthú chun raon sonraí a chóipeáil go huathoibríoch chuig áit nua. De réir mar a athrófar na sonraí go minic, ní mór duit an Macra seo a rith go huathoibríoch gach 5 nóiméad gan iad a spreagadh de láimh d’fhonn an dá raon sonraí seo a shioncronú. Conas é a bhaint amach? Is féidir le modh san alt seo cabhrú leat.

Déan Macra arís agus lúb gach X nóiméad in Excel


Déan Macra arís agus lúb gach X nóiméad in Excel

Is féidir leis an gcód VBA seo a leanas cabhrú leat Macra a athdhéanamh gach X nóiméad in Excel. Déan mar a leanas le do thoil.

1. Brúigh Eile + F11 eochracha ag an am céanna chun an Microsoft Visual Basic d’Fheidhmchláir fhuinneog.

2. Sa Microsoft Visual Basic d’Fheidhmchláir fuinneog, cliceáil le do thoil Ionsáigh > Modúil. Ansin cóipeáil agus greamaigh an cód VBA thíos sa cód fuinneog. Féach an pictiúr:

Cód VBA: Déan Macra arís agus lúb gach X nóiméad in 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

nótaí: Sa chód, cuir an líne seo ina áit 'Cuir isteach do chód anseo leis an gcód rithfidh tú gach X nóiméad.

3. Brúigh an F5 eochair chun an cód a rith. Sa popping suas Kutools le haghaidh Excel bosca dialóige, cuir isteach an t-am eatramh a dhéanfaidh tú an macra arís bunaithe ar, agus ansin cliceáil ar an OK cnaipe. Féach an pictiúr:

As seo amach, rithfidh an Macra áirithe arís agus arís eile gach 5 nóiméad i do leabhar oibre.

nótaí: Más gá duit stop a chur le forghníomhú na macra agus eatramh an timthrialla a athrú, cóipeáil an cód VBA thíos sa chéanna Modúil fuinneog agus brúigh an F5 eochair chun an cód a rith. Ansin stadfar an Macra, athcheangail an cód thuas le do thoil chun eatramh nua a shonrú.

Cód VBA: Stop forghníomhú na macra

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

Cluaisín Oifige - Brabhsáil Tabbed, Eagarthóireacht agus Bainistiú Leabhair Oibre in Excel:

Tugann Office Tab an comhéadan tabbed mar atá le feiceáil i mbrabhsálaithe gréasáin mar Google Chrome, leaganacha nua Internet Explorer agus Firefox chuig Microsoft Excel. Uirlis sábhála ama a bheidh ann agus ní féidir é a chur ar ais i do chuid oibre. Féach thíos an taispeántas:

Cliceáil le triail saor in aisce a dhéanamh ar Office Tab!

Cluaisín Oifige le haghaidh Excel


Earraí gaolmhara:


Na hUirlisí Táirgiúlachta Oifige is Fearr

Réitíonn Kutools for Excel an chuid is mó de do chuid Fadhbanna, agus Méadaíonn sé do Tháirgiúlacht 80%

  • Athúsáid: Cuir isteach go tapa foirmlí casta, cairteacha agus aon rud a d'úsáid tú roimhe seo; Cealla a Chriptiú le pasfhocal; Cruthaigh Liosta Ríomhphoist agus seol ríomhphoist ...
  • Barra Foirmle Super (cuir línte iolracha téacs agus foirmle in eagar go héasca); Leagan Amach Léitheoireachta (líon mór cealla a léamh agus a chur in eagar go héasca); Greamaigh go dtí an Raon Scagtha...
  • Cumaisc Cealla / Sraitheanna / Colúin gan Sonraí a chailleadh; Ábhar Cealla Scoilt; Comhcheangail Sraitheanna / Colúin Dúblacha... Cill Dúblach a Chosc; Déan comparáid idir Ranganna...
  • Roghnaigh Dúblach nó Uathúil Sraitheanna; Roghnaigh Blank Rows (tá na cealla uile folamh); Aimsigh Super agus Fuzzy Aimsigh i go leor Leabhar Oibre; Roghnaigh go randamach ...
  • Cóip Díreach Cealla Il gan tagairt fhoirmle a athrú; Tagairtí Cruthaigh Auto chuig Bileoga Il; Cuir Urchair isteach, Boscaí Seiceála agus go leor eile ...
  • Sliocht Téacs, Cuir Téacs leis, Bain de réir Poist, Bain Spás; Subtotals Paging a chruthú agus a phriontáil; Tiontaigh Idir Ábhar Cealla agus Tráchtanna...
  • Scagaire Super (scéimeanna scagaire a shábháil agus a chur i bhfeidhm ar bhileoga eile); Ard-Sórtáil de réir míosa / seachtaine / lae, minicíocht agus níos mó; Scagaire Speisialta le cló trom, iodálach ...
  • Comhcheangail Leabhair Oibre agus Bileoga Oibre; Cumaisc Táblaí bunaithe ar eochaircholúin; Roinn Sonraí i Ilbhileoga; Baisc Tiontaigh xls, xlsx agus PDF...
  • Níos mó ná 300 gné chumhachtach. Tacaíochtaí Office / Excel 2007-2019 agus 365. Tacaíonn sé le gach teanga. Imscaradh éasca i d’fhiontar nó d’eagraíocht. Gnéithe iomlána triail saor in aisce 30 lá. Ráthaíocht ar ais airgid 60 lá.
cluaisín kte 201905

Tugann Tab Oifige comhéadan Tabbed chuig Office, agus Déan Do Obair i bhfad Níos Éasca

  • Cumasaigh eagarthóireacht agus léamh tabbed i Word, Excel, PowerPoint, Foilsitheoir, Rochtain, Visio agus Tionscadal.
  • Oscail agus cruthaigh cáipéisí iolracha i gcluaisíní nua den fhuinneog chéanna, seachas i bhfuinneoga nua.
  • Méadaíonn do tháirgiúlacht 50%, agus laghdaíonn sé na céadta cad a tharlaíonn nuair luch duit gach lá!
bun officetab
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 · 1 months 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 · 7 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 · 7 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 · 8 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 · 8 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.