我是vba for excel的新手。
我试图在每次打开excel文件至少60秒时自动关闭和保存它。
到目前为止,我有这个代码。但是当文件打开60秒时它不会执行,除非我手动运行宏。非常感谢任何改进它的帮助。
Public Sub Workbook_Open()
Application.OnTime Now + TimeValue("00:00:60"),"ThisWorkbook.TimeOutSaveAndClose"
End Sub
Public Sub TimeOutSaveAndClose()
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.Quit
End Sub
答案 0 :(得分:0)
这应该为你解决。你必须打电话给另一个子。另外,请确保将其另存为启用宏的文件
Public Sub Workbook_Open()
Application.Wait (Now + TimeValue("0:00:60"))
call TimeOutSaveAndClose
End Sub
Public Sub TimeOutSaveAndClose()
Application.DisplayAlerts = False
ThisWorkbook.Save
Application.Quit
End Sub