每 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() 中,您确实选择了工作表,但没有激活它。只有在激活它之后才会进行切换。

相关内容