Forum Discussion
Importing CSV files with VBA Excel
Yes, it's possible to import CSV files into your worksheets. Though I'm afraid I don't follow why you want to read the filenames into a listbox first (you could add a command button to a worksheet and just get the filenames and copy the data in)?
I attached a file with a userform and some basic code to read filenames into a listbox. Also, I added a button to import two files. Though these two buttons are, at present, independent of each other (the import button will also have you browse for the files - I don't know what mechanism you plan to use for the import function to open the files since the listbox will only have the file name and not the path).
Hello JMB17,
I hope you are well.
I have checked and tested your VBA code in my XLSM file, and it works perfectly.
Eventually, I have deleted ListBox and others CommandButtons on my original UserForm.
Really, thank you very much, you helped me a lot on the part where I was blocking for a long time.
Have a nice day.
- JMB17Sep 06, 2020Bronze ContributorYou're welcome, I'm glad to hear you are able to move forward on your project.
- SebInfoFRSep 06, 2020Copper Contributor
Yes, and you help me on another point: my first MultiSelect:=True (on Application.GetOpenFileName) of my code didn't work because I had declared the variable "fNames" (taking the example of your XLSM) As String (I had only learned this option).
I hadn't thought to explore other options availabled, including As Variant.I'm still quite a beginner, so I have a lot to learn about VBA, and Excel in general.
I think this software is really powerful and efficient.