Vider des fichiers de leurs contenus VBA
Résolu/Fermé
A voir également:
- Vider des fichiers de leurs contenus VBA
- Wetransfer gratuit fichiers lourd - Guide
- Explorateur de fichiers - Guide
- Renommer plusieurs fichiers - Guide
- Incompatibilité de type vba ✓ - Forum Programmation
- Vba range avec variable ✓ - Forum VB / VBA
1 réponse
C bon j'ai trouvé une réponse en remaniant un code trouver sur internet, voici la réponse à mon problème si un jour quelqu'un en a besoin :
Sub VideFichier()
Const Chemin = "G:\...........\"
Dim oFs As Variant
Dim NomFichier As String
Dim I As Integer
Application.DisplayAlerts = False
Set oFs = Application.FileSearch
With oFs
.LookIn = Chemin
.FileType = msoFileTypeExcelWorkbooks
If .Execute > 0 Then
'MsgBox "Il y a " & .FoundFiles.Count & " fichier(s) de trouvé."
For I = 1 To .FoundFiles.Count
NomFichier = .FoundFiles(I)
If Right(NomFichier, 8) = "abcd.xls" Then
Workbooks.Open Filename:=NomFichier
Workbooks(Right(NomFichier, 12)).Activate
For Each mafeuille In Worksheets
If mafeuille.Name <> "ne pas supprimer" And Worksheets.Count > 1 Then
mafeuille.Delete
End If
Next
ActiveWorkbook.Close True
End If
Next I
Else
MsgBox "Aucun fichier n'a été trouvé."
End If
End With
'MsgBox "Fin de recherche"
Application.DisplayAlerts = False
End Sub
Private Sub CommandButton3_Click()
Dim mafeuille As Object
Call VideFichier
MsgBox "les fichiers ont été vidés"
End Sub
ici je supprime tous les onglets qui ne s'appellent pas "ne pas supprimer"
voilà!
Sub VideFichier()
Const Chemin = "G:\...........\"
Dim oFs As Variant
Dim NomFichier As String
Dim I As Integer
Application.DisplayAlerts = False
Set oFs = Application.FileSearch
With oFs
.LookIn = Chemin
.FileType = msoFileTypeExcelWorkbooks
If .Execute > 0 Then
'MsgBox "Il y a " & .FoundFiles.Count & " fichier(s) de trouvé."
For I = 1 To .FoundFiles.Count
NomFichier = .FoundFiles(I)
If Right(NomFichier, 8) = "abcd.xls" Then
Workbooks.Open Filename:=NomFichier
Workbooks(Right(NomFichier, 12)).Activate
For Each mafeuille In Worksheets
If mafeuille.Name <> "ne pas supprimer" And Worksheets.Count > 1 Then
mafeuille.Delete
End If
Next
ActiveWorkbook.Close True
End If
Next I
Else
MsgBox "Aucun fichier n'a été trouvé."
End If
End With
'MsgBox "Fin de recherche"
Application.DisplayAlerts = False
End Sub
Private Sub CommandButton3_Click()
Dim mafeuille As Object
Call VideFichier
MsgBox "les fichiers ont été vidés"
End Sub
ici je supprime tous les onglets qui ne s'appellent pas "ne pas supprimer"
voilà!