XL 2010 archiver le travail

saddoud w

XLDnaute Nouveau
Bonjour,

J’ai un problème … je désire archiver mon travail et effacé des feuilles …. Alors pour effacer les feuilles j’ai trouvé une solution mais je veux que mon classeur soit copié avec un nouveau nom avant d’effacer les feuilles … je pose un exemple pour mieux comprendre …merci d’avance
 

Pièces jointes

  • test.xlsm
    25.2 KB · Affichages: 9
Solution
bonsoir
change tout le code de ta feuil1 pour celui ci
adapte le chemin

VB:
Private Sub CommandButton1_Click()
    ActiveSheet.Range("a1") = [a1] + 1
    ThisWorkbook.ActiveSheet.Copy After:=Worksheets(Worksheets.Count)
    ActiveSheet.Name = "test " & ActiveSheet.Range("a1")
    ActiveSheet.DrawingObjects.Delete
End Sub

Private Sub CommandButton2_Click()
    Dim Wsh As Worksheet, chemin
    chemin = ThisWorkbook.Path & "\archive_du_" & Format(Now, "yyyy-mm-dd-hh-mm-ss") & ".xlsm"
    ThisWorkbook.SaveCopyAs chemin
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    For Each Wsh In ThisWorkbook.Worksheets
        If Wsh.Name <> "Feuil1" And Wsh.Name <> "Feuil2" And Wsh.Name <> "Feuil3" Then...

Eric KERGRESSE

XLDnaute Occasionnel
Bonjour,



VB:
Private Sub CommandButton2_Click()

Dim xWs As Worksheet

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    With ActiveWorkbook
        .SaveCopyAs .Path & "\" & .Sheets("Feuil1").Range("A1") & " " & GroupeDateHeure & ".xlsm"
        For Each xWs In .Worksheets
            If xWs.Name <> "Feuil1" And xWs.Name <> "Feuil2" And xWs.Name <> "Feuil3" Then xWs.Delete
        Next
    End With
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True


End Sub

Dans un module standard

Code:
Function GroupeDateHeure()

Dim DateDeCreation
Dim HeureEnCours As Variant

    DateDeCreation = Year(Date) & "-" & Format(Month(Date), "00") & "-" & Format(Day(Date), "00")
    HeureEnCours = Split(Time, ":")
    GroupeDateHeure = DateDeCreation & " " & Join(HeureEnCours, "-")

End Function
 
Dernière édition:

saddoud w

XLDnaute Nouveau
Bonjour,



VB:
Private Sub CommandButton2_Click()

Dim xWs As Worksheet

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    With ActiveWorkbook
        .SaveCopyAs .Path & "\" & .Sheets("Feuil1").Range("A1") & " " & GroupeDateHeure & ".xlsm"
        For Each xWs In .Worksheets
            If xWs.Name <> "Feuil1" And xWs.Name <> "Feuil2" And xWs.Name <> "Feuil3" Then xWs.Delete
        Next
    End With
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True


End Sub

Dans un module standard

Code:
Function GroupeDateHeure()

Dim DateDeCreation
Dim HeureEnCours As Variant

    DateDeCreation = Year(Date) & "-" & Format(Month(Date), "00") & "-" & Format(Day(Date), "00")
    HeureEnCours = Split(Time, ":")
    GroupeDateHeure = DateDeCreation & " " & Join(HeureEnCours, "-")

End Function

bonjour ...
malheureusement ça n'a pas marché .... rien ne se passe

 

patricktoulon

XLDnaute Barbatruc
bonsoir
change tout le code de ta feuil1 pour celui ci
adapte le chemin

VB:
Private Sub CommandButton1_Click()
    ActiveSheet.Range("a1") = [a1] + 1
    ThisWorkbook.ActiveSheet.Copy After:=Worksheets(Worksheets.Count)
    ActiveSheet.Name = "test " & ActiveSheet.Range("a1")
    ActiveSheet.DrawingObjects.Delete
End Sub

Private Sub CommandButton2_Click()
    Dim Wsh As Worksheet, chemin
    chemin = ThisWorkbook.Path & "\archive_du_" & Format(Now, "yyyy-mm-dd-hh-mm-ss") & ".xlsm"
    ThisWorkbook.SaveCopyAs chemin
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    For Each Wsh In ThisWorkbook.Worksheets
        If Wsh.Name <> "Feuil1" And Wsh.Name <> "Feuil2" And Wsh.Name <> "Feuil3" Then
            Wsh.Delete
        End If
    Next
    Feuil1.Activate
End Sub
 

saddoud w

XLDnaute Nouveau
bonsoir
change tout le code de ta feuil1 pour celui ci
adapte le chemin

VB:
Private Sub CommandButton1_Click()
    ActiveSheet.Range("a1") = [a1] + 1
    ThisWorkbook.ActiveSheet.Copy After:=Worksheets(Worksheets.Count)
    ActiveSheet.Name = "test " & ActiveSheet.Range("a1")
    ActiveSheet.DrawingObjects.Delete
End Sub

Private Sub CommandButton2_Click()
    Dim Wsh As Worksheet, chemin
    chemin = ThisWorkbook.Path & "\archive_du_" & Format(Now, "yyyy-mm-dd-hh-mm-ss") & ".xlsm"
    ThisWorkbook.SaveCopyAs chemin
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    For Each Wsh In ThisWorkbook.Worksheets
        If Wsh.Name <> "Feuil1" And Wsh.Name <> "Feuil2" And Wsh.Name <> "Feuil3" Then
            Wsh.Delete
        End If
    Next
    Feuil1.Activate
End Sub

merci beaucoup c'est génial :)
 

Membres actuellement en ligne

Statistiques des forums

Discussions
312 229
Messages
2 086 425
Membres
103 206
dernier inscrit
diambote