انتقل إلى المحتوى الرئيسي

كيفية تكرار أو تكرار ماكرو كل X دقيقة في إكسيل؟

أثناء العمل مع Microsoft Excel ، قد تحتاج إلى إنشاء وحدات ماكرو لتحقيق بعض العمليات. على سبيل المثال ، تريد إنشاء ماكرو لنسخ نطاق من البيانات تلقائيًا إلى مكان جديد. نظرًا لأنه سيتم تغيير البيانات بشكل متكرر ، فأنت بحاجة إلى تشغيل هذا الماكرو تلقائيًا كل 5 دقائق دون تشغيله يدويًا من أجل مزامنة هذين النطاقين من البيانات. كيف تحقق ذلك؟ الطريقة في هذه المقالة يمكن أن تساعدك.

كرر أو قم بتكرار ماكرو كل X دقيقة في Excel


كرر أو قم بتكرار ماكرو كل X دقيقة في Excel

يمكن أن تساعدك التعليمات البرمجية لـ VBA التالية على تكرار ماكرو كل X دقيقة في Excel. الرجاء القيام بما يلي.

1. صحافة قديم + F11 مفاتيح في نفس الوقت لفتح ميكروسوفت فيسوال باسيك للتطبيقات نافذة.

2. في ال ميكروسوفت فيسوال باسيك للتطبيقات نافذة ، الرجاء الضغط إدراج > وحدة. ثم انسخ والصق رمز VBA أدناه في ملف رمز نافذة او شباك. انظر لقطة الشاشة:

رمز فبا: كرر أو قم بتكرار ماكرو كل X دقيقة في إكسيل

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

ملاحظات: في الكود ، يرجى استبدال هذا السطر أدخل الرمز الخاص بك هنا باستخدام الكود ، ستعمل كل X دقيقة.

3. اضغط على F5 مفتاح لتشغيل الكود. في ظهرت كوتولس ل إكسيل في مربع الحوار ، يرجى إدخال الفاصل الزمني الذي ستكرر فيه الماكرو بناءً على ، ثم انقر فوق OK زر. انظر لقطة الشاشة:

من الآن فصاعدًا ، سيتم تشغيل الماكرو المحدد بشكل متكرر كل 5 دقائق في المصنف الخاص بك.

ملاحظات: إذا كنت بحاجة إلى إيقاف تنفيذ الماكرو وتغيير الفاصل الزمني للدورة ، فيرجى نسخ رمز VBA أدناه إلى نفسه وحدة نافذة واضغط على F5 مفتاح لتشغيل الكود. ثم سيتم إيقاف الماكرو ، يرجى إعادة تشغيل الكود أعلاه لتحديد فترة زمنية جديدة.

كود فبا: وقف تنفيذ الماكرو

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

تبويب أوفيس - الاستعراض المبوب وتحرير وإدارة المصنفات في Excel:

يجلب Office Tab الواجهة المبوبة كما تظهر في متصفحات الويب مثل Google Chrome والإصدارات الجديدة من Internet Explorer و Firefox إلى Microsoft Excel. ستكون أداة موفرة للوقت ولا يمكن الاستغناء عنها في عملك. انظر أدناه التجريبي:

انقر للحصول على نسخة تجريبية مجانية من Office Tab!

تبويب Office لبرنامج Excel


مقالات ذات صلة:

أفضل أدوات إنتاجية المكتب

🤖 مساعد Kutools AI: إحداث ثورة في تحليل البيانات على أساس: التنفيذ الذكي   |  إنشاء التعليمات البرمجية  |  إنشاء صيغ مخصصة  |  تحليل البيانات وإنشاء الرسوم البيانية  |  استدعاء وظائف Kutools...
الميزات الشعبية: البحث عن التكرارات أو تمييزها أو تحديدها   |  حذف الصفوف الفارغة   |  دمج الأعمدة أو الخلايا دون فقدان البيانات   |   جولة بدون صيغة 
سوبر بحث: معايير متعددة VLookup    VLookup ذات القيمة المتعددة  |   VLookup عبر أوراق متعددة   |   بحث غامض ....
قائمة منسدلة متقدمة: إنشاء القائمة المنسدلة بسرعة   |  القائمة المنسدلة التابعة   |  قائمة منسدلة متعددة التحديد ....
مدير العمود: إضافة عدد محدد من الأعمدة  |  نقل الأعمدة  |  تبديل حالة رؤية الأعمدة المخفية  |  مقارنة النطاقات والأعمدة 
الميزات المميزة: التركيز على الشبكة   |  عرض تصميم   |   شريط الفورمولا الكبير    مدير المصنفات والأوراق   |  مكتبة الموارد (النص السيارات)   |  منتقي التاريخ   |  اجمع أوراق العمل   |  تشفير/فك تشفير الخلايا    إرسال رسائل البريد الإلكتروني عن طريق القائمة   |  سوبر تصفية   |   مرشح خاص (تصفية غامق / مائل / يتوسطه خط ...) ...
أفضل 15 مجموعة أدوات12 نص الأدوات (إضافة نص, إزالة الأحرف، ...)   |   +50 رسم الأنواع (مخطط جانت، ...)   |   40+ عملي الصيغ (احسب العمر على أساس تاريخ الميلاد، ...)   |   19 إدخال الأدوات (أدخل رمز الاستجابة السريعة, إدراج صورة من المسار، ...)   |   12 تحويل الأدوات (أرقام إلى كلمات, نتيجة تحويل عملة، ...)   |   7 دمج وتقسيم الأدوات (الجمع بين الصفوف المتقدمة, تقسيم الخلايا، ...)   |   ... و اكثر

عزز مهاراتك في Excel باستخدام Kutools for Excel، واختبر كفاءة لم يسبق لها مثيل. يقدم Kutools for Excel أكثر من 300 ميزة متقدمة لتعزيز الإنتاجية وتوفير الوقت.  انقر هنا للحصول على الميزة التي تحتاجها أكثر...

الوصف


يجلب Office Tab الواجهة المبوبة إلى Office ، ويجعل عملك أسهل بكثير

  • تمكين التحرير والقراءة المبوبة في Word و Excel و PowerPointوالناشر والوصول و Visio والمشروع.
  • فتح وإنشاء مستندات متعددة في علامات تبويب جديدة من نفس النافذة ، بدلاً من النوافذ الجديدة.
  • يزيد من إنتاجيتك بنسبة 50٪ ، ويقلل مئات النقرات بالماوس كل يوم!
Comments (32)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
klo mengulang Makro sebanyak 3 kali, atau seberapa kali yang kita mau, itu gi mana yahh ? trima kasih sebelumny...
This comment was minimized by the moderator on the site
Hi Rizal,

The following VBA code can help. Please give it a try. Thank you.
Notes: In the code, you need to configure the following lines to meet your needs:
1) In this line: If Val(xNum) = 3 Then
Here the number 3 represents the number of times you want to repeat the macro. After three times looping, the macro will stop. Please change it to the number of times you need.
2) In this line: Application.OnTime Now() + TimeValue("0:" + "0" + ":10"), "ReRunMacro"
The number 10 here means that the macro will repeat every 10 seconds. You can specify the hours, minutes and seconds as you need.
Sub ReRunMacro()
'Updated by Extendoffice 20230203
Dim xMin As String
Dim xNum As String
'Insert your code here

Dim xRg As Range
    Dim xCell As Range
    Dim I As Long
    Dim J As Long
    Dim K As Long
    I = Worksheets("Sheet1").UsedRange.Rows.Count
    J = Worksheets("Sheet2").UsedRange.Rows.Count
    If J = 1 Then
    If Application.WorksheetFunction.CountA(Worksheets("Sheet2").UsedRange) = 0 Then J = 0
    End If
    Set xRg = Worksheets("Sheet1").Range("C1:C" & I)
    On Error Resume Next
    Application.ScreenUpdating = False
    For K = 1 To xRg.Count
        If CStr(xRg(K).Value) = "Done" Then
            xRg(K).EntireRow.Copy Destination:=Worksheets("Sheet2").Range("A" & J + 1)
            J = J + 1
        End If
    Next
    Application.ScreenUpdating = True

    xMin = GetSetting(AppName:="Kutools", Section:="Macro", Key:="min", Default:="")
    xNum = GetSetting(AppName:="Kutools", Section:="Macro", Key:="Num", Default:="")
    If xMin = "Exit" Then
    SaveSetting "Kutools", "Macro", "min", "False"
    Exit Sub
    End If
    
    If xNum = "" Then xNum = "1"
    If Val(xNum) = 3 Then 'Here the number 3 represents the number of times you want to repeat the macro. After three times looping, the macro will stop
        xNum = 1
        SaveSetting "Kutools", "Macro", "Num", "1"
        Application.OnTime EarliestTime:=TimeValue("17:00:00"), Procedure:="ReRunMacro", Schedule:=False
        Exit Sub
    End If
    xNum = Str(Val(xNum) + 1)
    SaveSetting "Kutools", "Macro", "Num", xNum

    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:" + "0" + ":10"), "ReRunMacro" 'The number 10 here means that the macro will repeat every 10 seconds. You can specify the hours, minutes and seconds as you need.
    Else
      Exit Sub
    End If
End Sub
This comment was minimized by the moderator on the site
please make repetitions for the following commands, thanks..

Sheets("Sisa").Select
Range("D2:D12000").Copy
Range("E2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Input").Select
Range("A3").End(xlDown).Offset(1, 0).FormulaR1C1 = "=R[-1]C+1"
Range("A3").End(xlDown).Offset(0, 21).Select
ActiveCell.FormulaR1C1 = _
"=IFERROR(IF(RC[-17]="""",VLOOKUP(RC[-18]&VLOOKUP(RC[-15],Kayu!C[-20]:C[-19],2,)&RC[-13]+RANDBETWEEN(1,3)&""Belum LHP"",Sisa!C[-21]:C[-14],8,),RC[-17]),"""")"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A3").End(xlDown).Offset(0, 22).Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]="""",IFERROR(VLOOKUP(RC[-19]&VLOOKUP(RC[-16],Kayu!C[-21]:C[-20],2,)&RC[-14]+1&""Belum LHP"",Sisa!C[-22]:C[-15],8,),""""),RC[-1])"
Range("A3").End(xlDown).Offset(0, 23).Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]="""",IFERROR(VLOOKUP(RC[-20]&VLOOKUP(RC[-17],Kayu!C[-22]:C[-21],2,)&RC[-15]+2&""Belum LHP"",Sisa!C[-23]:C[-16],8,),""""),RC[-1])"
Range("A3").End(xlDown).Offset(0, 24).Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]="""",IFERROR(VLOOKUP(RC[-21]&VLOOKUP(RC[-18],Kayu!C[-23]:C[-22],2,)&RC[-16]+3&""Belum LHP"",Sisa!C[-24]:C[-17],8,),""""),RC[-1])"
Range("A3").End(xlDown).Offset(0, 25).Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]="""",IFERROR(VLOOKUP(RC[-22]&VLOOKUP(RC[-19],Kayu!C[-24]:C[-23],2,)&RC[-17]+4&""Belum LHP"",Sisa!C[-25]:C[-18],8,),""""),RC[-1])"
Range("A3").End(xlDown).Offset(0, 26).Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]="""",IFERROR(VLOOKUP(RC[-23]&VLOOKUP(RC[-20],Kayu!C[-25]:C[-24],2,)&RC[-18]+5&""Belum LHP"",Sisa!C[-26]:C[-19],8,),""""),RC[-1])"
Range("A3").End(xlDown).Offset(0, 4).Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[22]="""",IFERROR(VLOOKUP(RC[-1]&VLOOKUP(RC[2],Kayu!C[-3]:C[-2],2,)&RC[4]+0&""Belum LHP"",Sisa!C[-4]:C[3],8,),""""),RC[22])"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
This comment was minimized by the moderator on the site
Compile error:

Expected End Sub

Mam przekopiowane dokładnie jak jest napisane wyzej i nie moge odnaleźć problemu
This comment was minimized by the moderator on the site
Hi Pawid,
Can you provide a screenshot of the error and the highlighted row in the vba code? The problem could not be reproduced in my case. Sorry for the inconvinience.
This comment was minimized by the moderator on the site
In Excel 365 I'm getting a Run-time error '13' Type mismatch on the following line: Application.OnTime Now() + TimeValue("0:" + "0:" + xMin), "ReRunMacro"
This comment was minimized by the moderator on the site
Hi Ron Franklin,I tried  it in Excel 365, but this problem could not be reproduced. 
This comment was minimized by the moderator on the site
có cách nào dừng macro khi tắt file và macro tự khởi động lại khi mở lại file không add
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
Good day,You need to remove the Sub line and the End Sub line from your code.<div data-tag="code">Sub Refresh()
'
' Refresh Macro
'

'
Sheets("Sheet1").Select
ActiveWorkbook.RefreshAll
Sheets("Pivot-Dash").Select
End SubChange to:<div data-tag="code">'
' Refresh Macro
'

'
Sheets("Sheet1").Select
ActiveWorkbook.RefreshAll
Sheets("Pivot-Dash").Select
This comment was minimized by the moderator on the site
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?
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
How to create a macro in excel with continuous loop and pressed key would be only pg up and pg down
This comment was minimized by the moderator on the site
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?
This comment was minimized by the moderator on the site
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?
This comment was minimized by the moderator on the site
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
This comment was minimized by the moderator on the site
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.
This comment was minimized by the moderator on the site
Hello, Just help me out on "insert your code here". I am a novice and need help on what to fill and how ! ThanksI am not getting it right
This comment was minimized by the moderator on the site
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.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations