Gather all file names from a file path

tuktuk

Well-known Member
Joined
Nov 13, 2006
Messages
856
hye there,

is there a way to write code in a module to import all .xls file name from a static filepath.

append to a tbl_AllxlsFiles.

it kind of a strange request but i really dont know where to start except for:

define the FilePath....

<gathere the file names>

use an insert into table stepping thru the recordset.

thanks
tuktuk
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
i guess ii don't know what that is then. i thought that was my "theFilePath = "G:\TUKTUK\3BrandReporting\AgentLevel\36MonthHistorical\"".

tuk
 
Upvote 0
so in my example above (or the code i mirrored) would i use:

ChDir ("\\Servername\directory\directory2\")
theFilePath = "\\Servername\directory\directory2\"

but for some reason i still cant locate the /csv

thanks
tuk
 
Upvote 0
tuk

Could you please post all the code?
 
Upvote 0
sure thing

Code:
Public Sub ImportAllFilesFromPath()

Dim strfile As String
Dim theFilePath As String
Dim theFileName As String

ChDir ("\\hqintl1.com\general\FDCC04\HOME\Dept\Me\AdHocReporting\dtf\IMPORT_Test\")
theFilePath = "\\hqintl1.com\general\FDCC04\HOME\Dept\Me\AdHocReporting\dtf\IMPORT_Test\"

strfile = Dir("*.csv")
Do While Len(strfile) > 0
theFileName = Left(Dir("*.CSV"), Len(Dir("*.CSV")) - 4)
DoCmd.TransferText acImportFixed, "Specs", theFileName, theFilePath & strfile, True
strfile = Dir
Loop
End Sub
 
Upvote 0
Try using the UNC path with Dir.

ie Dir(theFilePath & "*.csv")
 
Upvote 0
hey Norie...it worked. NICE!!!!

Now i'm attetmpting to acutally import the files from the lan.

Joe4 previously in this post told me to name the Import Spec to Mappings while importing one of the file manually.

My quesiton is can I import the first file, then run code and at the end of that code deleted the imported file.....then go to the next csv from the lan import to that table,,,,run code etc until i pass through all csvs?

i tried not setting "theFileName" in the code above and then changed the Transferstatemetn to:

"DoCmd.TransferText acImportFixed, "mappings", "ImportedFilesFormLAN", theFilePath & strfile, True"......

but that didn't work.

any ideas?

tuktuk
 
Upvote 0
Why do you not want to use the filename?

In fact you need to use something for the name of the table you are importing to.

So unless you want to import into a specific, existing table you should stick with what you've got - for now at least.

You might end up with multiple tables but at least that would be a start.

Importing the first file and then importing into the table that creates isn't totally straightforward.

It would probably be easier to create a blank table, with all correct fields etc, and import all the files into that.

Another thing you might want to consider is how are you going to identify which records come from which CSV file.

That might not be important, hard to tell without more information about the data, but in my experience it's sometimes the most important thing.:)
 
Upvote 0

Forum statistics

Threads
1,215,030
Messages
6,122,762
Members
449,095
Latest member
m_smith_solihull

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