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 62 63 64 65 66 67 68 69 70 71 72 73
| Private Sub CommandButton1_Click()
On Error Resume Next
Dim chemin As String, KRCFile As String
Dim folder As Variant, box As Variant
Dim NBFichier As Integer
Dim wb As Workbook
Dim CopyTarget As Range
Dim FillTarget As Range
Dim SourceValue As Range
Const FillColumn = 10 'REMPLACER LE NUMERO DE LA COLONNE DANS LAQUELLE EST COPIEE LA VALEUR FIXE ICI
'définit le répertoire contenant les fichiers
chemin = ThisWorkbook.Path & Application.PathSeparator
folder = "KRC_GB-BH\"
'tous les fichiers krc*.xlsx du folder
KRCFile = Dir(chemin & folder & "KRC" & "*.xlsx")
If KRCFile <> "" Then
'boucle => nombre de fichiers trouvés dans le folder
While Not KRCFile = ""
NBFichier = NBFichier + 1
KRCFile = Dir
Wend
Else: MsgBox "Not Files in the folder"
Exit Sub
End If
box = MsgBox("Find" & " " & NBFichier & " " & "file(s)" & " " & "?", vbYesNo + vbQuestion + vbApplicationModal + vbDefaultButton2, "")
KRCFile = Dir(chemin & folder & "KRC" & "*.xlsx")
If box = vbYes Then
If KRCFile <> "" Then
Application.StatusBar = "Old data erased"
sh_globalkrc("A5:O" & ActiveSheet.UsedRange.Rows.Count - 1).ClearContents
Application.StatusBar = "Import in progess....."
Application.ScreenUpdating = False
Do While KRCFile <> ""
Application.EnableEvents = False
'ouvre le fichier trouvé
Set wb = Workbooks.Open(chemin & folder & KRCFile, local:=True, ReadOnly:=True)
If feuil2.Range("k3") = "oui / ja" Then
feuil2.Range("B13:N" & ActiveSheet.UsedRange.Rows.Count).Copy
Set CopyTarget = sh_globalkrc.Range("A1048576").End(xlUp).Offset(1, 0)
CopyTarget.PasteSpecial Paste:=xlPasteValues, operation _
:=xlNone, skipblanks:=False, Transpose:=False
Set FillTarget = sh_globalkrc.Range(Cells(CopyTarget.Row, FillColumn), Cells(sh_globalkrc.Range("A1048576").End(xlUp).Row, FillColumn))
Set SourceValue = feuil2.Range("A1") 'MODIFIER L'ADRESSE DE LA PLAGE SOURCE ICI
FillTarget = SourceValue.Value
'vide le presse papier
Call ClearClipboard
End If
'ferme le fichier trouvé en cours
wb.Close True
Set wb = Nothing
KRCFile = Dir
Loop
MsgBox "Import OK"
Columns("A:O").AutoFit
Application.Goto reference:=Range("A5")
Application.ScreenUpdating = True
Application.StatusBar = False
Application.EnableEvents = True
End If
End If
End Sub |
Partager