Sub Macro1()
Dim chemin$, fichier$, Frécent$, x$, y$, z$
fichier = "Articles manquants pour approche - "
chemin = "V:\Commun\Appros\Fichier Simplifié"
x = Format(Date, "-mm"): y = Format(Date, "-dd"): z = Format(Date, "yyyy")
1 If FileExiste(chemin & "\" & fichier & z & x & y & ".xls") Then
Workbooks.Open (chemin & "\" & fichier & z & x & y & ".xls")
Else
If z = 2000 Then Exit Sub
If x = -1 And y = -1 Then
z = z - 1: x = -12: y = -31: GoTo 1
End If
If y = -1 Then
y = -31: x = x + 1: GoTo 1
Else
y = y + 1: GoTo 1
End If
End If
' Fichier le plus récent :
Frécent = fichier & z & x & y & ".xls"
Windows("MACRO Fichier Simplifié.xls").Activate
Range("P2").Select
Selection.Value = "[" & Frécent & "]" & "Feuil1!C8:C15"
Range("O2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-7],INDIRECT(R2C16),8,0)"
Range("O2").Select
Selection.AutoFill Destination:=Range("O2:O500")
Columns("O:O").Select
Selection.Copy
'Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows(Frécent).Activate
ActiveWindow.Close
End Sub
Function FileExiste(nom$) As Boolean
FileExiste = Dir(nom) <> ""
End Function