Bonjour,
En cherchant sur le net, j'ai trouvé une macro qui me permet de copier des fichiers dans un classeur et les renomme d'une certaine manière (ex : nom du fichier Tata - 2022, nom de l'onglet Toto. une fois la copie faite il doit s'appeler Tata - 2022.xlsx(Toto)). Globalement elle fonctionne bien mais il y a parfois des loupés, elle ne garde que le nom de l'onglet. Pourriez-vous m'aider à la fiabiliser.
Ah oui, je suis débutant dans le codage
Voici le code :
Je vous remercie par avance pour votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 Sub Récup_Fichier() 'Updated by Extendoffice 2019/2/20 Dim xStrPath As String Dim xStrFName As String Dim xWS As Worksheet Dim xMWS As Worksheet Dim xTWB As Workbook Dim xStrAWBName As String On Error Resume Next xStrPath = "P:\FINANCE\COMPTA\xxx\" xStrFName = Dir(xStrPath & "*.xlsx") Application.ScreenUpdating = False Application.DisplayAlerts = False Set xTWB = ThisWorkbook Do While Len(xStrFName) > 0 Workbooks.Open Filename:=xStrPath & xStrFName, ReadOnly:=True xStrAWBName = ActiveWorkbook.Name For Each xWS In ActiveWorkbook.Sheets xWS.Copy After:=xTWB.Sheets(xTWB.Sheets.Count) Set xMWS = xTWB.Sheets(xTWB.Sheets.Count) xMWS.Name = xStrAWBName & "(" & xMWS.Name & ")" Next xWS Workbooks(xStrAWBName).Close xStrFName = Dir() Loop Application.ScreenUpdating = True Application.DisplayAlerts = True Worksheets("Acompte_Solde").Select MsgBox "Traitement Terminé" End Sub
Partager