LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
JRP JRP is offline
external usenet poster
 
Posts: 3
Default File list - list filenames in excel

Hi, I have tryed this code listed below and it work, but as you see it only
list files in folder spesifyed in: .LookIn = ...

what I want to do is to find files from a dialogbox.

Any of you who can tell me how?????
--------------------------------------------------------------
Function CreateFileList(FileFilter As String, _
IncludeSubFolder As Boolean) As Variant
' returns the full filename for files matching
' the filter criteria in the current folder
Dim FileList() As String, FileCount As Long
CreateFileList = ""
Erase FileList
If FileFilter = "" Then FileFilter = "*.*" ' all files
With Application.FileSearch
.NewSearch
.LookIn = "C:\My Documents"
.Filename = FileFilter
.SearchSubFolders = IncludeSubFolder
.FileType = msoFileTypeAllFiles
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) = 0 Then Exit Function
ReDim FileList(.FoundFiles.Count)
For FileCount = 1 To .FoundFiles.Count
FileList(FileCount) = .FoundFiles(FileCount)
Next FileCount
.FileType = msoFileTypeExcelWorkbooks ' reset filetypes
End With
CreateFileList = FileList
Erase FileList
End Function

Sub TestCreateFileList()
Dim FileNamesList As Variant, i As Integer
'ChDir "C:\Levende"
' activate the desired startfolder for the filesearch
FileNamesList = CreateFileList("*.*", False)
' performs the filesearch, includes any subfolders
' present the result
Range("A:A").ClearContents
For i = 1 To UBound(FileNamesList)
Cells(i + 4, 3).Formula = FileNamesList(i)
Next i
End Sub
-----------------------------------------------------------------------------
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
List Filenames from Folder Eskimo Excel Programming 1 May 19th 06 08:41 PM
List all filenames & tab names Deeds Excel Worksheet Functions 5 May 18th 06 11:16 PM
Getting a list of filenames Tom Ogilvy Excel Programming 3 April 13th 05 04:31 PM
Getting a list of filenames Bernie Deitrick Excel Programming 0 April 13th 05 02:55 PM
List out FileNames.xls with K4 Blank JMay Excel Programming 4 December 7th 03 04:35 PM


All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"