File picker / Compiler

Diena

New Member
Joined
Jun 12, 2023
Messages
4
Office Version
  1. 2021
Platform
  1. Windows
  2. MacOS
Hello everyone, I need help with the code below.
fOLDER PICKER.png

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
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I think you're right. I've only dabbled with VBA on the MacBook and found it unbearably painful. I think what you have there is the Windows approach to the filepath, whereas Mac is different. I think if you go to FileFinder, locate the file and you will see it's full path at the bottom of the FileFinder window. right click and copy as path and paste that in. See if that helps.

Also, are you sure that's a file? It looks like a folder.
 
Upvote 0
I think you're right. I've only dabbled with VBA on the MacBook and found it unbearably painful. I think what you have there is the Windows approach to the filepath, whereas Mac is different. I think if you go to FileFinder, locate the file and you will see it's full path at the bottom of the FileFinder window. right click and copy as path and paste that in. See if that helps.

Also, are you sure that's a file? It looks like a folder.
Thanks, you are right it's a folder. but the macro still don't work even with the right path, i really don't know how to do.
 
Upvote 0
Well, a couple of things.
1. If there is an error, and you're asking for help, you need to identify which line VBA says is the problematic line (you've done that) but also tell us the error number and the error message (you have yet to do that).
2. The code you've posted above is different to the code in the screen capture. Please make sure that the two are exactly the same.
3. You may have provided the correct path to a folder, but that's not what the Picker does, nor is it what the property requires. It's a file picker, and the property is InitialFileName... So you need to give it a valid filename... Not folder path.

Also, if you've changed the path and initalfilename details so that it's Mac compatible, and you're still experiencing errors, please make sure you post the updated code.
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,824
Members
449,190
Latest member
rscraig11

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top