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
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