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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| Sub Test()
'''''''''''''''''''''''''''''''
'''Compte nombre de fichier pour la boucle
Dim Chemin As String
Dim i As Integer
Dim FileName As String
Chemin = "fullpath"
Set ofso = CreateObject("Scripting.FileSystemObject")
Set oFolder = ofso.GetFolder(Chemin)
Set oFiles = oFolder.Files
Dim x As Integer
For Each file In oFiles
''''''''''''''''''''''''''''''''''''''
Dim sFichier As String 'chemin du fichier source
Dim oWBSource As Workbook 'fichier source
Dim oShSource As Worksheet 'onglet source
Dim oShCible As Worksheet 'onglet où on récupère
Dim FullName As String
FileName = file.Name
FullName = Chemin + "\" + FileName
'chemin du fichier source
sFichier = FullName
'vérif existe
If Dir(sFichier) = "" Then
MsgBox "Fichier absent : " & vbCrLf & sFichier, vbExclamation
Exit Sub
End If
'cet onglet
Set oShCible = Worksheets(1)
'ouverture en lecture seule
Set oWBSource = Workbooks.Open(sFichier, , True)
'onglet
Set oShSource = Worksheets(2) 'voir quel onglet on veut traiter
'récupération d'une valeur (exemple)
oShSource.Range("B2:F100000").Copy
oShCible.Cells(oShCible.Cells(Rows.Count, 1).End(xlUp).Row + 1, 1).PasteSpecial (xlPasteValues)
'fermeture sans enregistrer
oWBSource.Close False
Set oShSource = Nothing
Set oWBSource = Nothing
Set oShCible = Nothing
Next
End Sub |
Partager