Hello everyone, I need help with the code below.
The problem is the path to the file, but the path is correct because I simply copied and pasted it directly.
I think the problem may come from the fact that I have a mac book ?
thanks in advance
The problem is the path to the file, but the path is correct because I simply copied and pasted it directly.
I think the problem may come from the fact that I have a mac book ?
VBA Code:
Sub Import_Data()
Dim Wkb As Workbook
Dim i As Integer
Dim fenChoix As FileDialog
Dim cptlign As Integer
Dim NbrOperation As Integer
Set fenChoix = Application.FileDialog(msoFileDialogFilePicker)
cptlign = 10
NbrOperation = 0
'nettoyer les données
'nettoyer
Range("A10:A1000000").ClearContents
If Range("C10") <> "" Then Range("C10").CurrentRegion.Clear
' Vérifier si la boîte de dialogue est affichée et des fichiers sont sélectionnés
If fenChoix.Show = -1 Then
With fenChoix
'Parametrer fenetre de choix
'.InitialFileName = "C:\Users\my ID\Desktop\Cours VBA\Bases de ventes"
.AllowMultiSelect = True
.Filters.Clear
.Filters.Add "Excel", "*.xls*", "*.xlsm*"
For i = 1 To .SelectedItems.Count
'Pour chaque fichier
NbrOperation = NbrOperation + 1
'afficher le nom
Cells(9 + i, 1) = .SelectedItems(i)
'ouvrir le fichier
Set Wkb = Workbooks.Open(.SelectedItems(i))
'coller
If NbrOperation = 1 Then
Wkb.Sheets(1).Range("A1").CurrentRegion.Copy ThisWorkbook.ActiveSheet.Range("C" & cptlign)
'adapter nbr de ligne present
cptlign = cptlign + Wkb.Sheets(1).Range("A1").CurrentRegion.Rows.Count
Else
Wkb.Sheets(1).Range("A1").CurrentRegion.Offset(1).Resize(Wkb.Sheets(1).Range("A1").CurrentRegion.Offset(1).Rows.Count - 1).Copy ThisWorkbook.ActiveSheet.Range("C" & cptlign)
'adapter nbr de ligne present
cptlign = cptlign + Wkb.Sheets(1).Range("A1").CurrentRegion.Rows.Count - 1
End If
'fermer
Wkb.Close (False)
Set Wkb = Nothing
Next i
End With
Else
' L'utilisateur a annulé la sélection ou aucun fichier n'a été choisi
MsgBox "Aucun fichier sélectionné.", vbInformation
End If
Set fenChoix = Nothing
End Sub
thanks in advance