Forum Discussion
Importing CSV files with VBA Excel
Hello, is VBA really necessary for this task? I mean, Excel has Power Query feature that you can specify a folder where your CSV files are stored and you can manage all them more easily than by coding.
Hello Juliano,
Thank you for your reply.
In my first post, I forgot some details. My apologies.
My XLSM file will finally used by my workteam (and me) every month (I work in an IT support). And I have 4 exported files every month from our AD (by PowerShell).
Well, my idea is to use VBA with a UserForm for the import and layout of these files, using CommandButton, for quickly processing of AD data later.
Our main job is to resolve user issues, but we are also responsible for the entry and exit of employees, with different procedures.
I started creating my XLSM file in consultation with my manager, for faster management of employee outings, while respecting our procedures.
It is for this purpose that I thought I would use VBA Excel for quick layouts (I think it is possible, but I'm not sure).
Well, I just need to know if it is possible to import csv files into each sheet by their names because I'm blocking on that. I can manage afterwards for the layout.
Do you think it is possible by VBA? Or with Power Query fast enough?
- JMB17Aug 30, 2020Bronze Contributor
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).
- SebInfoFRSep 05, 2020Copper Contributor
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.
- SebInfoFRAug 31, 2020Copper Contributor
Hello JMB17,
Thanks for your reply, and thanks for your file. I will visualize it as soon as I have time (working this week, I might have a lot of work).
I keep you informed of the continuation.
For my 2nd question, it was just to show only the file names in ListBox, to make it more intuitive for my workteam. But if that is not possible, it's not important.