在未修改XXX时间的情况下删除工作表

问题: 有没有办法可以删除未修改'X'天数的工作表? 或者将我们的活动工作簿中的不活动页面转移到档案簿中?

我正在开发一个项目,其中包含所有活动工作表(由作业#生成)并汇总所包含的数据。 工作表名称都是可变的,并根据填充到主工作表中的数据生成。

一旦工作完成,该工作表可能永远不需要再次访问。

我感谢任何见解!

坚持这个在你的ThisWorkbook对象。 它将更新工作簿上任何工作表中所做更改的跟踪器工作表( Sheet1 )。 然后在开始时,如果date差异大于一周,那么它将(当取消注释时)删除表单。 改变这个,如果你想做一些不同的事情

 Option Explicit Private Sub Workbook_Open() Dim rng As Range Dim DayDiff As Long Dim c DayDiff = 7 ' Update this to the sheet that you want to keep your timestamp list With Sheet1 Set rng = .Range(.Cells(1, 1), .Cells(.Cells(.Rows.Count, 1).End(xlUp).Row, 1)) Application.DisplayAlerts = False For Each c In rng If c.Offset(0, 1) < Now() - DayDiff Then Debug.Print c 'ThisWorkbook.Sheets(c.Value2).Delete 'Range(c, c.Offset(0, 1)).Delete End If Next c Application.DisplayAlerts = True End With End Sub Private Sub Workbook_SheetChange(ByVal sh As Object, ByVal Target As Range) Dim rng As Range Dim c ' Update this to the sheet that you want to keep your timestamp list With Sheet1 If Not sh.Name = .Name Then Set rng = .Range(.Cells(1, 1), .Cells(.Cells(.Rows.Count, 1).End(xlUp).Row, 1)) Set c = rng.Find(sh.Name) If Not c Is Nothing Then c.Offset(0, 1) = Now() Else With .Cells(.Cells(.Rows.Count, 1).End(xlUp).Row + 1, 1) .Value2 = sh.Name .Offset(0, 1) = Now() End With End If End If End With End Sub