我有一个始终打开的 xlsm 工作簿 wscopy 和工作簿始终关闭的 wsdest
我希望它在不打开的情况下将 wscopy 工作表中的所有值复制到已关闭的工作簿,并且每 30 秒自动执行一次。
我收到以下错误:在 application.ontime 代码中“参数不是可选的”
有什么帮助吗?
Sub clear_existing_data_before_paste()
Dim wscopy As Worksheet
Dim wsdest As Worksheet
Dim lcopyLastrow As Long
Dim ldestLastrow As Long
Application.OnTime Now + TimeValue("00:00:30")
With Application
.ScreenUpdating = False
End With
Set wscopy = ThisWorkbook.Worksheets("NEWROUND")
Set wsdest = Workbooks.Open("E:\FORMS\DELEGATION APPLICATION\2-2023\DATABASE-2-2023.xlsm").Worksheets("All Data")
lcopyLastrow = wscopy.Cells(wscopy.Rows.Count, "A").End(xlUp).Row
ldestLastrow = wsdest.Cells(wsdest.Rows.Count, "a").End(xlUp).Offset(1).Row
wsdest.Range("A2:N" & ldestLastrow).ClearContents
wscopy.Range("a2:n" & lcopyLastrow).Copy wsdest.Range("a2")
wsdest.Parent.Save
wsdest.Parent.Close True
With Application
.ScreenUpdating = True
End With
End Sub
application.ontime
函数需要两个参数,什么时候运行,运行什么。您需要将您的 sub 添加到代码中作为“运行参数”,例如。
Application.OnTime Now + TimeValue("00:00:30"), clear_existing_data_before_paste