1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| Public Sub JeCopieOuJeVeux()
Dim i As Integer
Dim sSQL As String, sNomFic As String, sChemin As String, sNomFeuille As String, sValCell As String
Dim ObjExcel As Excel.Application
Dim MaFeuille As Excel.Worksheet
Dim MonClasseur As Excel.Workbook
On Error GoTo err_JeCopieOuJeVeux
sChemin = "H:\DATA\Développement\Prev_ventes\sauvegarde frank"
'Définition des critères de recherche des fichiers : - Location
' - Recherche dans les sous-dossiers
' - Type de fichier
With Application.FileSearch
.NewSearch
.LookIn = sChemin '"H:\DATA\Développement\Prev_ventes\sauvegarde frank"
.SearchSubFolders = True
'.Filename = "*"
.FileType = msoFileTypeExcelWorkbooks
'si on trouve des fichiers correspondant au critère
If .Execute() > 0 Then
MsgBox "Il y a " & .FoundFiles.Count & _
" fichier(s) correspondant aux critères voulus.", vbInformation
'Récupération du nom du fichier
For i = 1 To .FoundFiles.Count
sNomFic = .FoundFiles.Item(i)
'MsgBox "Le fichier qui va être ouvert est " & sNomFic & " !", vbInformation
'Instanciation de l'objet Excel
Set ObjExcel = New Excel.Application
'Ouverture du fichier
ObjExcel.Workbooks.Open sNomFic, False, False, , "", "", True
'pas de messages d'alerte
ObjExcel.DisplayAlerts = False
'pas de messages demandant de faire la mise à jour des liens
ObjExcel.ActiveWorkbook.UpdateLinks = xlUpdateLinksNever
ObjExcel.Visible = True
ObjExcel.DisplayAlerts = True
Set MaFeuille = ObjExcel.ActiveWorkbook.Worksheets(1)
For Each MaFeuille In ObjExcel.ActiveWorkbook.Worksheets |
Partager