gpt4 book ai didi

excel - VBA 宏初学者 - 如何使以下代码在任务之间停止和启动?

转载 作者:行者123 更新时间:2023-12-04 22:30:44 24 4
gpt4 key购买 nike

我是一个完全的初学者,没有接受过正规的编码教育。下面给出的是我编写的 VBA 代码。我在启用宏的 Excel 工作表中运行它。在每个 Action 之后,代码会等待 10 分钟,然后再进行下一个 Action 。但是,在那 10 分钟内,我无法对 Excel 表进行任何手动更改,因为宏一直处于“等待模式”。有什么办法可以让宏停止运行,然后在 10 分钟后重新开始?这样我就可以在过渡期间对 Excel 工作表进行更改。

此外,只要输出保持不变,欢迎任何其他优化代码的建议。非常感谢。

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B8").Select
ActiveSheet.Paste
Range("A5").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B11").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B14").Select
ActiveSheet.Paste
Range("A11").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B17").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B20").Select
ActiveSheet.Paste
Range("A17").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B23").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B26").Select
ActiveSheet.Paste
Range("A23").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B29").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B32").Select
ActiveSheet.Paste
Range("A29").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B35").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B38").Select
ActiveSheet.Paste
Range("A35").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B41").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B44").Select
ActiveSheet.Paste
Range("A41").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B47").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B50").Select
ActiveSheet.Paste
Range("A47").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B53").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B56").Select
ActiveSheet.Paste
Range("A53").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B59").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B62").Select
ActiveSheet.Paste
Range("A59").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B65").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B68").Select
ActiveSheet.Paste
Range("A65").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B71").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B74").Select
ActiveSheet.Paste
Range("A71").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B77").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B80").Select
ActiveSheet.Paste
Range("A77").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B83").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B86").Select
ActiveSheet.Paste
Range("A83").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B89").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B92").Select
ActiveSheet.Paste
Range("A89").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B95").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B98").Select
ActiveSheet.Paste
Range("A95").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B101").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B104").Select
ActiveSheet.Paste
Range("A101").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B107").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B110").Select
ActiveSheet.Paste
Range("A107").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B113").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B116").Select
ActiveSheet.Paste
Range("A113").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B119").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B122").Select
ActiveSheet.Paste
Range("A119").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B125").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B128").Select
ActiveSheet.Paste
Range("A125").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B131").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B134").Select
ActiveSheet.Paste
Range("A131").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B137").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B140").Select
ActiveSheet.Paste
Range("A137").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B143").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B146").Select
ActiveSheet.Paste
Range("A143").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B149").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B152").Select
ActiveSheet.Paste
Range("A149").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B155").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B158").Select
ActiveSheet.Paste
Range("A155").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B161").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B164").Select
ActiveSheet.Paste
Range("A161").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B167").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B170").Select
ActiveSheet.Paste
Range("A167").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B173").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B176").Select
ActiveSheet.Paste
Range("A173").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B179").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B182").Select
ActiveSheet.Paste
Range("A179").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B185").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B188").Select
ActiveSheet.Paste
Range("A185").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B191").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B194").Select
ActiveSheet.Paste
Range("A191").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B197").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B200").Select
ActiveSheet.Paste
Range("A197").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B203").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B206").Select
ActiveSheet.Paste
Range("A203").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B209").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B212").Select
ActiveSheet.Paste
Range("A209").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B215").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B218").Select
ActiveSheet.Paste
Range("A215").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"
Application.Wait DateAdd("s", 580, Now)

Sheets("NSE Data").Select
Selection.QueryTable.Refresh BackgroundQuery:=False
Application.Wait DateAdd("s", 15, Now)
Range("B48:V50").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B221").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("NSE Data").Select
Range("B1").Select
Selection.Copy
Sheets("2nd Nov").Select
Range("B224").Select
ActiveSheet.Paste
Range("A221").Select
ActiveCell.Value = Time
ActiveCell.NumberFormat = "h:mm AM/PM"`

最佳答案

您可以将您的代码分解为更模块化的代码,其中每个子程序都做一件事,并将其与 Application.OnTime 一起使用以按时间间隔执行每个子程序

Option Explicit

Public Sub test()
Dim t As Date
t = Time
Application.OnTime t + TimeSerial(0, 0, 10), "a"
Application.OnTime t + TimeSerial(0, 0, 20), "b"
End Sub

Public Sub a()
Debug.Print "A"
End Sub

Public Sub b()
Debug.Print "B"
End Sub

循环执行 5 行:
Option Explicit
Public Sub test()
Dim t As Date, i As Long
For i = 1 To 5
t = Time
Application.OnTime t + TimeSerial(0, 0, i * 10), "'a """ & i * 5 & """'"
Next
End Sub

Public Sub a(ByVal rowNumber As Long)
Debug.Print Cells(rowNumber, 1).Address
End Sub

关于excel - VBA 宏初学者 - 如何使以下代码在任务之间停止和启动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53141186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com