Sub CreerFeuillesMoisSuivant()
Dim F As Worksheet, jour&, nf$, w As Worksheet, i%, j%
Set F = Sheets("Tableau")
Application.ScreenUpdating = False
On Error Resume Next
For jour = DateSerial(Year(Date), Month(Date) + 1, 1) To DateSerial(Year(Date), Month(Date) + 2, 0)
nf = Format(jour, "yyyy-mm-dd")
Set w = Nothing
Set w = Sheets(nf)
If w Is Nothing Then 'si la feuille n'existe pas on la crée
F.Copy After:=F
ActiveSheet.Name = nf
ActiveSheet.Range("B4").NumberFormat = "yyyy-mm-dd"
ActiveSheet.Range("B4") = jour
ActiveSheet.DrawingObjects.Delete
End If
Next
'---tri des feuilles---
For i = F.Index + 1 To Sheets.Count
For j = i + 1 To Sheets.Count
If Sheets(j).Name < Sheets(i).Name Then Sheets(j).Move Before:=Sheets(i)
Next j, i
Sheets(Format(DateSerial(Year(Date), Month(Date) + 1, 1), "yyyy-mm-dd")).Activate
End Sub
Sub Imprimer()
Dim x$, test1 As Boolean, test2 As Boolean, s, dat1&, dat2&, jour&, nf$, w As Worksheet
Do
x = InputBox("Entrez la 1ère et la dernière date séparées par un espace :", "Imprimer", x)
If x = "" Then Exit Sub
test1 = False: test2 = False
s = Split(Trim(x))
If UBound(s) > 0 Then test1 = IsDate(s(0)): test2 = IsDate(s(1))
Loop While Not test1 Or Not test2
dat1 = Int(CDate(s(0))): dat2 = Int(CDate(s(1)))
On Error Resume Next
For jour = Application.Min(dat1, dat2) To Application.Max(dat1, dat2)
nf = Format(jour, "yyyy-mm-dd")
Set w = Nothing
Set w = Sheets(nf)
If Not w Is Nothing Then w.PrintOut 'w.PrintPreview 'pour tester
Next
End Sub