bonjour,
je vous expllique simplement :
Je souhaite lors de l'enregistrement d'un fichier qu'il verifie au prealable s'il est existant avant de l'enregistrer et si c 'est le cas il annule l'enregistrement.
Je n'y arrive vraiment pas .. je vous laisse mon code pour que sa vous aide ..
cordialement
je vous expllique simplement :
Je souhaite lors de l'enregistrement d'un fichier qu'il verifie au prealable s'il est existant avant de l'enregistrer et si c 'est le cas il annule l'enregistrement.
Je n'y arrive vraiment pas .. je vous laisse mon code pour que sa vous aide ..
cordialement
Code:
Private Sub save_Click()
Dim X, occurence As Integer
Dim R As Range
Dim ligne As Long
Dim trouve As Boolean 'déclare la variable trouvé
Dim chr, chr1 As String
Dim question As Long
If cbproduit = "" Then
question = MsgBox("Entrer un nom Produit !", vbCritical, "Information Manquante")
End If
trouve = False
occurence = 0
ligne = 1
Label_Alerte = ""
'=======================================================
'Recherche les produits parmis les primaires
'=======================================================
Set R = ThisWorkbook.Sheets("primaire").Range("A:A").Find(what:=cbproduit.Value, LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlNext)
If Not R Is Nothing Then trouve = True
For Each R In ThisWorkbook.Sheets("primaire").Range("A65536:A" & ThisWorkbook.Sheets("primaire").Range("A:A").End(xlDown).Row)
If R.Text = cbproduit.Value Then
Workbooks.Open "C:\Documents and Settings\s558670\Bureau\modele_fiche_suiveuse.xlsx"
With ThisWorkbook
occurence = 0
Range("C5").Value = .Sheets("primaire").Range("D" & R.Row).Value
Range("C6").Value = .Sheets("primaire").Range("C" & R.Row).Value
Range("G5").Value = .Sheets("primaire").Range("A" & R.Row).Value
Range("G6").Value = .Sheets("primaire").Range("P" & R.Row).Value
Range("G7").Value = .Sheets("primaire").Range("I" & R.Row).Value
Range("A10").Value = .Sheets("primaire").Range("AJ" & R.Row).Value
Range("B10").Value = .Sheets("primaire").Range("J" & R.Row).Value
Range("C10").Value = .Sheets("primaire").Range("K" & R.Row).Value
Range("D10").Value = .Sheets("primaire").Range("R" & R.Row).Value
Range("E10").Value = .Sheets("primaire").Range("T" & R.Row).Value
Range("F10").Value = .Sheets("primaire").Range("S" & R.Row).Value
Range("G10").Value = utilisation
End With
End If
Next R
occurence = 0
End If
chr = Range("format!G5")
chr1 = Range("format!C5")
ChDrive "c"
ChDir "C:\Documents and Settings\s558670\Bureau\"
ActiveWorkbook.SaveAs Filename:=(chr) & "_" & (chr1)
question = MsgBox("voulez vous visualiser la fiche suiveuse ?", vbYesNo + vbQuestion, " Suggestion ")
If question = vbYes Then
Workbooks.Open "C:\Documents and Settings\s558670\Bureau\" & chr & "_" & chr1 & ".xlsx"
End If
If question = vbNo Then
ActiveWorkbook.Close
End If
Unload fiche_suivi
End Sub