How Can I generate a List of files in a given directory?

G

Guest

I want to look up file names in a given directory and then list those fiels
in an excel spreadsheet.

I want to look in "C:\...\" for all *.txt files.
put file path, name, and extension in a table called files.
the table has only one field.
then
I would like to export the table to excel and then delete the table.

I have tried several of the solutions for this, but nothing works.

The only purpose this db has is to create this list.

Please help.

Matthew
 
G

Guest

Why not do it directly from Excel? You could write a macro in VBA using the
FileSearch Object and get the same results without having to go through
Access.
 
G

Guest

I have the code to do it in excel, but want to do it from Access for this and
future requirements because what they want to do is really better handled by
access.

Matthew
 
G

Guest

Try using the Filesearch Object.

Here is an example of it using VBA code:

Dim fs As FileSearch
Set fs = Application.FileSearch

With fs
.NewSearch
.LookIn = sdir
.FileType = msoFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
For i = 1 To .FoundFiles.Count
FullFileName = .FoundFiles(i)
MsgBox "File: " & .foundFiles(i), vbInformational, "File Found"
Next i
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top