每 10 秒在工作表之間移動一次,並每 20 分鐘在一個程式碼中引入數據

每 10 秒在工作表之間移動一次,並每 20 分鐘在一個程式碼中引入數據

我需要一個腳本,每 10 秒在工作表之間切換一次,然後每 20 分鐘運行一些程式碼,使用複製貼上功能帶來一些數據,然後循環直到我按「Esc」。

到目前為止,這是我的程式碼:

Sub Move_Between_Sheets()
  Dim i As Long, j As Long, t As Single, k As Long
  Application.ScreenUpdating = True
i = 0
  j = Sheets.Count
  On Error GoTo exit_
  Application.EnableCancelKey = xlErrorHandler

  Do
  For k = 1 To 3
    i = i + 1
    If i > j Then i = 1
    Sheets(i).Select
    t = Timer + 1
    Application.Wait Now + TimeSerial(0, 0, 10)
    If Timer < t Then Exit Do
  Next k
  Call BringPK03
  Loop
exit_:
End Sub 
------------------
Sub BringPK03()

Dim sheet As Worksheet
Dim wbPlantillas As Workbook
Dim wbAplicativo As Workbook

Set wbAplicativo = ThisWorkbook
 Application.ScreenUpdating = False
    'Application.Calculation = xlCalculationManual
'13. URL [Link]
'The database workbook is opened from WorkPoint. The sheets in database workbook are copied and pasted in wbAplicativo
   Set wbPlantillas = Workbooks.Open("C:\Users\jmartine\Desktop\Tracking Advance.xlsx", True, True)

   wbPlantillas.Sheets("FC Paso a Paso").Range("A1:AU4500").Copy

   wbAplicativo.Sheets("Sheet1").Range("A1:AO1573").PasteSpecial xlPasteValues
   Application.CutCopyMode = False

   wbPlantillas.Close savechanges:=False
   Windows("BringData.xlsm").Activate

   wbAplicativo.Worksheets("Sheet1").Activate
   Application.ScreenUpdating = True
   Range("A1").Select
   Call Move_Between_Sheets


End Sub

我的程式碼一直運行,直到函數 BringPK03 帶來資料並將其貼到我的工作簿中,然後程式碼繼續運行,但不知何故,工作表之間的移動不起作用。

答案1

在 Move_Between_Sheets() 中,您確實選擇了工作表,但沒有啟動它。只有啟動後才會進行切換。

相關內容