创build一个MS Excel文件,当达到某个时间或date时自动删除它

关于MS Excel,我想知道如何创build一个Excel文件,当某个date或时间到达时从计算机中删除。

可能吗? 如果是,请告诉我怎么做?

您可以在将来的特定时间调用函数DoSomething ,或者通过调用Activate_timer来指定时间间隔,但是我不认为您可以直接从VBA中删除工作簿。 您可以尝试在DoSomething函数中调用某个batch file ,先closures该书,然后将其删除。

 Sub Activate_timer() ' at a certain time in the future 'Application.OnTime DateSerial(2014,01,01)+TimeSerial(0,0,0), "DoSomething" ' or by specifying the time interval Application.OnTime Now + TimeValue("01:40:00"), "DoSomething" End Sub Sub DoSomething() 'call the batch file End Sub 

如果将此代码添加到ThisWorkbook模块,那么如果当前date晚于2014年1月1日,则工作簿将自毁。

 Private Sub Workbook_Open() If Now() > #1/1/2014# Then Call SuicideSub End Sub 

 Sub SuicideSub() 'courtesy Tom Ogilvy With ThisWorkbook .Saved = True .ChangeFileAccess xlReadOnly Kill .FullName .Close False End With End Sub