Fermer un fichier sans enregistrer

  • Initiateur de la discussion Initiateur de la discussion dam3117
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

dam3117

XLDnaute Occasionnel
Bonsoir au forum,

j'avais le msg d'erreur suivant: erreur d'exécution '1004'
la methode saveas de l'objet_workbook à échoué, suite à une reponse négative ou annuler au message voulez vous remplacer le fichier......
Donc j'ai ajouté les lignes suivantes dans ma macro

On Error Resume Next
If Err = 2042 Then
ActiveWorkbook.Close False

Exit Sub
End If

Maintenant il me ferme bien fichier qui porte le meme nom mais je voudrai egalement qu'il me ferme le fichier.xst sans l'enregistrer.

ci dessous ma macro.



Private Sub CommandButton2_Click()
Dim xlig As Long


Workbooks.Open Filename:= _
ThisWorkbook.Path & "\recap ctrl.xlt"
Windows("recap ctrl.xlt").Activate

Range("h1") = Label2
Range("h3") = Date

For x = 0 To ListBox1.ListCount - 1
For y = 0 To ListBox1.ColumnCount - 1
Sheets("Feuil1").Range("A15").Offset(x, y) = ListBox1.List(x, y)
Next y
Next x
Range("A14").Select
Selection.CurrentRegion.Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Cells.Select
Cells.EntireColumn.AutoFit
Cells.EntireRow.AutoFit
Range("A14").Select
Selection.Sort Key1:=Range("d14"), Order1:=xlAscending, Key2:=Range("e14") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom

Range("A14").Select
Label2.Caption = Format(Label2, "ddmmyy")
On Error Resume Next
If Err = 2042 Then
ActiveWorkbook.Close False

Exit Sub
End If
ActiveWorkbook.SaveAs Filename:="\\Svrgn2\Service peche\RECAP CTRL\" & "recap ctrl" & Label2.Caption & ".xls", FileFormat:= _
xlNormal, PASSWORD:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False


Unload Me
End Sub

merci d'avance
 
Re : Fermer un fichier sans enregistrer

Bonjour,

comprends pas trop ton problème, si tu veux créer un nouveau classeur sur la base d'un modèle, à mon avis le mieux serait de procéder ainsi :

Code:
Workbooks.Add Template:="C:\MesDocuments\Excel\MonModele.xlt"

Ou alors quelque chose m'a échappé, fort possible du reste...

bonne journée
@+
 
Re : Fermer un fichier sans enregistrer

Bonjour,
Pour le message d'erreur je mettrai en début de macro:

Application.DisplayAlerts = False

Pour quitter un fichier sans sauvegarde:

Workbooks("Mon_fichier").Close SaveChanges:=False

Cordialement
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

  • Question Question
Microsoft 365 worksheet_change
Réponses
29
Affichages
481
Réponses
2
Affichages
511
Réponses
17
Affichages
1 K
Réponses
4
Affichages
552
  • Question Question
Microsoft 365 Export données
Réponses
4
Affichages
650
Retour