Delay Excel save function

好久不见. 提交于 2019-12-25 02:02:16

问题


I have a workbook which requires to be saved at the beginning then auto saving every 5 mins, but i need to delay the initial save so that when the workbook opens it waits 30secs then does the save.

This is the code i have, but it runs it automatically:

Private Sub Workbook_Open()
Time = Now() + TimeValue("00:00:30")
Application.OnTime Time, "WaitUntilReady"

Public Sub WaitUntilReady()

savefolder = "C:\Users\" & Environ$("Username") & "\Desktop\"

mypath = savefolder & Format(Date, "dd-mmm-yy")

If Len(Dir(mypath, vbDirectory)) = 0 Then MkDir mypath

On Error Resume Next

ThisWorkbook.SaveAs mypath & "\" & "Practice Monitoring Template" & " - " & Format(Time, "hh.nn") & ".xlsm"

Application.EnableEvents = True
End Sub

回答1:


Time is reserved word in Excel (it returns current time), use this one instead:

Private Sub Workbook_Open()
    Application.OnTime Now() + TimeValue("00:00:30"), "WaitUntilReady"
End Sub



回答2:


Time is an ingegrated function. If you do not declare it as a variable, the line Time = ... should throw an error. If you have declared it, it should actually run fine (not immediately) - it does in my tests. (Of course you should rather change the variable name).



来源:https://stackoverflow.com/questions/22247259/delay-excel-save-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!