Import Multiple CSV Files from Same Folder into Open Workbook

  • Thread starter Thread starter conorfinnegan
  • Start date Start date
C

conorfinnegan

Thanks in advance for your help here.

I'm trying to automatically import some csv files into my Excel workbook. These files always have the same names and are stored within a folder wherethe Excel file is open. I need to have each file imported into a specifictab (if it exists). Not every file will be used and won't always be available for import so I'll need the VBA routine to skip and move on.

The tabs/worksheets I'd like to import to are called "DataToday", "DataTomorrow", "DataYesterday", and "DataMonthly". The csv files are named something close to the same.

Please let me know if more information is needed but I'm hoping this will be enough. Thanks again.

Conor Finnegan
 
VBA requires explicity, so "files are named something close..." isn't
going to cut it! There must be a reliable way to determine which files
get imported to which sheets!

What criteria will you use to determine which files get skipped?

Do you want to select a folder, or multi-select just the files to
import?

Is there any reason why each file can't be imported to its own sheet?

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
VBA requires explicity, so "files are named something close..." isn't

going to cut it! There must be a reliable way to determine which files

get imported to which sheets!



What criteria will you use to determine which files get skipped?



Do you want to select a folder, or multi-select just the files to

import?



Is there any reason why each file can't be imported to its own sheet?



--

Garry



Free usenet access at http://www.eternal-september.org

Classic VB Users Regroup!

comp.lang.basic.visual.misc

microsoft.public.vb.general.discussion

Hello Gary,

The sheet names and the file names will always be the same, but the file names won't match the sheet names exactly. So I just want to be able to say always take this file and import to this "specific" sheet.

As for skipping, sometimes I only want to import 3 of the files and other times I want to import 5 of the files. They will be contained in the same folder of the open workbook. So I was just going to edit the macro and maketwo different versions - one for the 3 files and one for the 5 files. Theuser would then run the specific macro they needed to run.

Let me know if you need anymore information here. Sorry for the confusion the first time around.

Thanks.

Conor
 
The sheet names and the file names will always be the same, but the
file names won't match the sheet names exactly. So I just want to be
able to say always take this file and import to this "specific"
sheet.

As for skipping, sometimes I only want to import 3 of the files and
other times I want to import 5 of the files. They will be contained
in the same folder of the open workbook. So I was just going to edit
the macro and make two different versions - one for the 3 files and
one for the 5 files. The user would then run the specific macro they
needed to run.

Can the user select the files they want, instead of 2 different macros?

Can you give examples of the filenames?

Where do you want to put the file contents on the target sheets? (ie:
below/above existing data, or replace existing data)

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
Can the user select the files they want, instead of 2 different macros?



Can you give examples of the filenames?



Where do you want to put the file contents on the target sheets? (ie:

below/above existing data, or replace existing data)



--

Garry



Free usenet access at http://www.eternal-september.org

Classic VB Users Regroup!

comp.lang.basic.visual.misc

microsoft.public.vb.general.discussion

I'd rather just have it pull all the files from the same folder. Those names don't change. They are called "DataToday", "DataTomorrow", "DataYesterday", and "DataMonthly". The sheet names are DataToday_TotalDelivery, DataTomorrow_Expected, etc. On import the data can overwrite the data that exists.

Hope that's the information you're looking for. Thanks again for your help.. Much appreciated.

Conor
 
I'd rather just have it pull all the files from the same folder.

You said the number of files each time will vary (3 or 5). Does this
mean that at any given time the folder will only contain the correct
number of files for processing? If so, this suggests you'll also need
to delete or rename or move the existing files. What's your preference?
In the case of rename/move specify the criteria details.

This folder can be set as the default for the browser. The user will
only see CSV files if that's what you want. Please confirm...
Those names don't change. They are called "DataToday",
"DataTomorrow", "DataYesterday", and "DataMonthly". The sheet names
are DataToday_TotalDelivery, DataTomorrow_Expected, etc.

So the filenames are...

DataToday.CSV
DataTomorrow.CSV
DataYesterday.CSV
DataMonthly.CSV

...and their target sheetnames contain *exactly* the same text left of
the ".CSV" part.
On import the data can overwrite the data that exists.

Easily done!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
Back
Top