If you are trying to make a list of files from a directory to a worksheet,
why not use filesearch? Here are a couple of examples.
Sub GetFileList2222()
Dim iCtr As Integer
With Application.FileSearch
.NewSearch
.LookIn = "c:\aa"
.SearchSubFolders = True
.Filename = ".xls"
If .Execute 0 Then
For iCtr = 1 To .FoundFiles.Count
Cells(iCtr, 1).Value = .FoundFiles(iCtr)
Next iCtr
End If
End With
End Sub
Sub FindandListFiles()
Application.ScreenUpdating = False
Columns(1).ClearContents
Dim FN As String ' For File Name
Dim ThisRow As Long
Dim FileLocation As String
FileLocation = "c:\keystone\*.xls"
FN = Dir(FileLocation)
Do Until FN = ""
ThisRow = ThisRow + 1
Cells(ThisRow, 1) = FN
FN = Dir
Loop
Application.ScreenUpdating = True
End Sub
--
Don Guillett
SalesAid Software
"Don Wiss" wrote in message
...
To read files from my hard disk into a spreadsheet I run a batch file
like:
dir "G:\My Music\Comedy\*.*" c:\temp.prn
pause
dir "G:\My Music\Compilations\*.*" c:\temp.prn
pause
dir "G:\My Music\Country\*.*" c:\temp.prn
pause
Then at each pause I change the focus to the spreadsheet and type Ctrl-H,
which runs the import macro. It would simplify things greatly if I could
issue the commands in a macro and have all run in one step. I know issuing
a command is easy in regular programming languages. What is involved to do
so in VBA? (I'm using Excel 2002.)
Don <donwiss at panix.com.