|
放在thisbook这个工作表对象内,在 VBE界面里的sheet对象下面,用保存前对比上次保存时间与现在时间是否跨天来判断是否增加工作表。- Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
- Dim N, I As Integer, sht As Worksheet, X As Integer
- N = WorksheetFunction.Text(Now() - ActiveWorkbook.BuiltinDocumentProperties(12), "D")
-
- If N > 0 Then
-
-
- I = ThisWorkbook.Sheets.Count
-
- For X = 1 To Sheets.Count
- If Worksheets(I).Name <> Format(Now(), "m-d") Then
- Worksheets(I).Copy after:=Worksheets(I)
- I = I + 1
- Worksheets(I).Name = Format(Now(), "m-d")
- MsgBox "发现保存文件时,已跨天,已自动创建今日工作表" & Worksheets(I).Name
- Exit Sub
- End If
- Next
-
- End If
- End Sub
- Private Sub Workbook_Open()
- Dim I As Integer, sht As Worksheet, X As Integer
- I = ThisWorkbook.Sheets.Count
-
- For X = 1 To Sheets.Count
- If Worksheets(I).Name <> Format(Now(), "m-d") Then
- Worksheets(I).Copy after:=Worksheets(I)
- I = I + 1
- Worksheets(I).Name = Format(Now(), "m-d")
- MsgBox "已创建今日工作表" & Worksheets(I).Name
- Exit Sub
- End If
- Next
- End Sub
-
复制代码 |
|