Problème de date VBA
bonjour le forum
j'ai ce code a l'ouverture du classeur pour faire une sauvegarde automatique du fichier dans un dossier .
le problème est quelle fonctionne avec une seul date mais quand j'en met plusieurs date elle ne fonctionne plus.
je suis obliger de choisir plusieurs jour car si je n'en choisi qu'un cela peux tomber sur un dimanche.
avez vous une solution a me proposer?
merci de votre aide
Private Sub Workbook_Open()
Sheets("Fiche site").Select
'j'efface la cellule P1 les 21-22-23-24 et 25 de chaque mois
If Day(Date) & "/" & Month(Date) & "/" & Year(Date) = "21/" & "22/" & "23/" & "24/" & Month(Date) & "/" & Year(Date) Then
Sheets("Fiche site").Range("P1").Clear
End If
Call RépertoireExiste("S:\Sauvegarde Fiche site")' appel de la macro pour verifier si le dossier existe sinon le créer
'sauvegarde a l'un de ces jours 25-26-27-28 de chaque mois
If Day(Date) & "/" & Month(Date) & "/" & Year(Date) = "25/" & "26/" & "27/" & "28/" & Month(Date) & "/" & Year(Date) Then
If Sheets("Fiche site").Range("P1").Value = "" Then
If MsgBox("Voulez-vous sauvegarder le fichier tout de suite ?", vbYesNo, "Attention") = vbYes Then
Sheets("Fiche site").Range("P1").Value = "Oui"
Dim Chemin As String, Fichier As String
Chemin = "S:\Sauvegarde Fiche site\"
'Ajoute la date du jour et l'heure dans le nom du fichier
Fichier = "Sauvegarde_Fiche_Site_du_" & Format(Date, "ddmmyyyy") & ".xlsm"
ActiveWorkbook.SaveCopyAs Chemin & Fichier
MsgBox ("Fichier SAUVEGARDER sur S:\Sauvegarde Fiche site")
End If
Else
'MsgBox "Pensez à sauvegarder ultérieurement."
'Sheets("Fiche site").Range("P1").Value = ""
End If
End If
End sub
g
Bonjour
Cette instruction est incorrecte :
If Day(Date) & "/" & Month(Date) & "/" & Year(Date) = "25/" & "26/" & "27/" & "28/" & Month(Date) & "/" & Year(Date) ThenRemplace la par :
If Day(Date) & "/" & Month(Date) & "/" & Year(Date) = "21/" & Month(Date) & "/" & Year(Date) _
Or Day(Date) & "/" & Month(Date) & "/" & Year(Date) = "22/" & Month(Date) & "/" & Year(Date) _
Or Day(Date) & "/" & Month(Date) & "/" & Year(Date) = "23/" & Month(Date) & "/" & Year(Date) _
Or Day(Date) & "/" & Month(Date) & "/" & Year(Date) = "24/" & Month(Date) & "/" & Year(Date) Thenou encore par :
If Date = DateSerial(Year(Date), Month(Date), 21) _ Or Date = DateSerial(Year(Date), Month(Date), 22) _ Or Date = DateSerial(Year(Date), Month(Date), 23) _ Or Date = DateSerial(Year(Date), Month(Date), 24) Then
Résultat ?
Bye !