Private Sub Workbook_Open()
Dim s As Object
If Day(Date) > 1 Then Exit Sub
Application.DisplayAlerts = False
On Error Resume Next 'si tous les noms commencent par CR...
For Each s In Sheets
If UCase(s.Name) Like "CR#*" Then s.Delete
Next
End Sub
Private Sub Workbook_Open()
If Day(Date) = 1 Then 'si le jour est le 1
For Each ws In ActiveWorkbook 'pour chaque feuille du classeur
If ws.name = "CR*" Then ws.Delete ' si son nom commence par CR, on la supprime..
Next ws
End If
End Sub
Private Sub Workbook_Open()
Dim DerSuppr As String, Asuppr As Boolean, rep, sh
On Error Resume Next
DerSuppr = Replace(ActiveWorkbook.Names("DateSuppr"), "=", "")
On Error GoTo 0
If DerSuppr = "" Then
Asuppr = MsgBox("pas de trace d'une ancienne suppression" & vbLf & vbLf & _
"Doit-on supprimer les feuilles 'CR nnn' ?", _
vbQuestion + vbYesNo + vbDefaultButton2) = vbYes
Else
Asuppr = Format(Date, "yyyymm") > DerSuppr
End If
If Asuppr Then
Application.DisplayAlerts = False: Application.ScreenUpdating = False
For Each sh In ThisWorkbook.Sheets
If LCase(sh.Name) Like "cr#*" Then
If ThisWorkbook.Sheets.Count = 1 Then
ThisWorkbook.Worksheets.Add
ThisWorkbook.ActiveSheet.Name = "XXX"
End If
sh.Delete
End If
Next sh
ThisWorkbook.Names.Add Name:="DateSuppr", RefersToR1C1:=Format(Date, "yyyymm"), Visible:=False
End If
Application.DisplayAlerts = True
End Sub
Private Sub Workbook_Open()
If FileDateTime(Me.FullName) > DateSerial(Year(Date), Month(Date), 1) Then Exit Sub '1er du mois à 00:00
Dim s As Object
Application.DisplayAlerts = False
On Error Resume Next 'si tous les noms commencent par CR...
For Each s In Sheets
If UCase(s.Name) Like "CR#*" Then s.Delete
Next
End Sub